前端面试可能出现的问题记录

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26983555/article/details/81166647

css面试题:

1、清楚浮动有哪些方式?比较好的方式是哪一种

•1、父级div定义height。
•2、结尾处加空div标签clear:both。
•3、父级div定义伪类:after和zoom。
•4、父级div定义overflow:hidden。
•5、父级div定义overflow:auto。
•6、父级div也浮动,需要定义宽度。
•7、父级div定义display:table。
•8、结尾处加br标签clear:both。

•比较好的是第3种,好多网站都这样用

2、CSS实现垂直水平居中

  1. .wrapper{position:relative;} //父级
    .content{
    background-color:#6699FF;
    width:200px;
    height:200px;
    position: absolute; //父元素需要相对定位
    top: 50%;
    left: 50%;
    margin-top:-100px ; //二分之一的height,width
    margin-left: -100px;
    }
  2. .content{
    width: 200px;
    height:200px;
    position: relative;
    border: 1px solid rebeccapurple;
    top:50%;
    left:50%;
    -webkit-transform: translate(-50%,-50%);
    -moz-transform: translate(-50%,-50%);
    -ms-transform: translate(-50%,-50%);
    -o-transform: translate(-50%,-50%);
    transform: translate(-50%,-50%);
    }

猜你喜欢

转载自blog.csdn.net/qq_26983555/article/details/81166647