慕课网《前端跳槽面试必备技巧》学习笔记

2018-12-09  本文已影响0人  冰淇wbq

关于面试

面试准备

面试技巧

题目:假设高度已知,请写出三栏布局,其中左栏、右栏宽度各为300px,中间自适应

方法一:display:flex
#container{
    display: flex;
    height: 100vh;
}
.left{
    width: 300px;
    background: red;
}
.content{
    flex: 1;
    background: darkcyan;
}
.right{
    width: 300px;
    background: red;
}
<article id="container">
    <div class="left"></div>
    <div class="content"></div>
    <div class="right"></div>
</article>
方法二:浮动
#container{
    min-height: 100px;
}
.left{
    float: left;
    width: 300px;
    background: red;
}
.content{
    background: darkcyan;
}
.right{
    float: right;
    width: 300px;
    background: red;
}
<article id="container">
    <div class="left"></div>
    <div class="right"></div>
    <div class="content"></div>
</article>
方法三:定位
*{
    margin: 0;
    padding: 0;
}
.left{
    position: absolute;
    top: 0;
    left: 0;
    width: 300px;
    height: 100vh;
    background: red;
}
.content{
    margin: 0 300px;
    height: 100vh;
    background: darkcyan;
}
.right{
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 100vh;
    background: red;
}
<article id="container">
    <div class="left"></div>
    <div class="right"></div>
    <div class="content"></div>
</article>
方法四:表格布局
*{
    margin: 0;
    padding: 0;
}
#contenter{
    display: table;
    width: 100%;
    min-height: 100px;
}
.left,.center,.right{
    display: table-cell;
}
.left{
    width: 300px;
    background: red;
}
.right{
    width: 300px;
    background: cornflowerblue;
}
<article id="contenter">
    <div class="left"></div>
    <div class="center">表格布局</div>
    <div class="right"></div>
</article>
方法五:网格布局
*{
    margin: 0;
    padding: 0;
}
#contenter{
    display: grid;
    width: 100%;
    grid-template-rows: 100px;
    grid-template-columns: 300px auto 300px;
}
.left{
    background: red;
}
.center{
    background: rebeccapurple;
}
.right{
    background: cornflowerblue;
}
<article id="contenter">
    <div class="left"></div>
    <div class="center">表格布局</div>
    <div class="right"></div>
</article>

flex布局:是比较完美的

表格布局:兼容性好

网格布局:新技术,代码量少

绝对定位解决方案:

浮动

  1. 在script标签上增加crossorigin属性
  2. 设置js资源响应头Access-Control-Allow-Origin
<script crossorigin  src="http://www.lmj.com/demo/crossoriginAttribute/error.js"></script>

res.setHeader("Access-Control-Allow-Origin","*");

题目演练

知识梳理

复习指导

课程价值

上一篇下一篇

猜你喜欢

热点阅读