css+html面试题面试前的准备

前端面试题总结一css篇

2018-11-01  本文已影响14人  明眸yh

面试题总结

1、请用css使一个div垂直居中

方法1:table-cell

html结构:

<div class="box box1">
    <span>垂直居中</span>
</div>

css:

.box1{
    display: table-cell;
    vertical-align: middle;
    text-align: center;        
}
方法2:display:flex
.box2{
    display: flex;
    justify-content:center;
    align-items:Center;
}
方法3:绝对定位和负边距
.box3{position:relative;}
.box3 span{
    position: absolute;
    width:100px;
    height: 50px;
    top:50%;
    left:50%;
    margin-left:-50px;
    margin-top:-25px;
    text-align: center;
}

2、请解释一下为什么要清除浮动?写出两种能清除浮动的方法

我们说的清除浮动是指清除由于子元素浮动带来父元素高度塌陷的影响。

3、介绍一下css盒模型

在网页中,一个元素占有空间的大小由几个部分构成,其中包括元素的内容(content),元素的内边距(padding),元素的边框(border),元素的外边距(margin)四个部分。这四个部分占有的空间中,有的部分可以显示相应的内容,而有的部分只用来分隔相邻的区域或区域。4个部分一起构成了css中元素的盒模型。

4、css中box-sizing可以设置哪些属性?

5、css中可以隐藏元素常用的方法?

6、css3transform和animation区别

.navButton{
   color:black;
  background-color:#fff;
  transition:color,background-color;
  transition-delay:1s, .5s;
}

.navButton:hover{
   color:red;
   background-color:#ccc;  
}

3)触发器:常用的触发器是几个伪类,:active,:target,:focus,也可以是前后两个类的改变。

animation
transition只能从一组css属性变成另一组css属性。animation则可以在多组属性之间变换。
transition必须使用触发器触发,animation可以使用触发器,也可以在页面加载完成的时候自动触发。
创建动画有两个步骤:
1).定义动画:主要指定义关键帧

@keyframes fadeIn{
   from{
      opacity:0;
  },
  to{
     opacity:1;   
 }
}

2)将动画应用到元素上
可以使用一下css属性定义动画:

.nav-button{
    animation-name:fadeIn;
    animation-duration:1s;
    animation-timing-function:ease-out,
    animation-delay:.5s;
    animation-iteration-count:infinite;  
    animation-direction:alternate
}

animation-name:和当初定义的动画名称相对应;
animation-duration:动画执行一次持续的时长;
animation-timing-function:动画速率变化函数;
animation-delay:动画延迟执行的时间长度;
animation-iteration-count:动画执行的次数,可以是数字,或者关键字:infinate(无限运行);
animation-direction:alternate; alternate(奇数次超前运行,偶数次后退运行).如希望动画从黄色到蓝色,并且再重复一次,使用alternate关键字就能够防止从蓝色突变为黄色
animation-fill-mode:告诉浏览器将元素的格式保持为动画结束时候的样子。

上一篇 下一篇

猜你喜欢

热点阅读