选择器的类型:css
表明内联样式,如style="xxx",权值为 1000;
表明 ID 选择器,如#content,权值为 100;
表明类、伪类和属性选择器,如.content、:hover、[attribute],权值为 10;
表明元素选择器和伪元素选择器,如div、p,权值为 1。布局
须要注意的是:通用选择器(*)、子选择器(>)和相邻同胞选择器(+)并不在这四个等级中,因此他们的权值都为 0。 权重值大的选择器其优先级也高,相同权重的优先级又遵循后定义覆盖前面定义的状况。动画
box-sizing属性:设计
div设置了box-sizing:border-box以后,width的宽度是内容 + padding + 边框的宽度(不包括margin),这样就比较符合咱们的实际要求了。code
float被设计出来的初衷是用于文字环绕效果,即一个图片一段文字,图片float:left以后,文字会环绕图片.
float 的破坏性 —— float 破坏了父标签的本来结构,使得父标签出现了坍塌现象。致使这一现象的最根本缘由在于:被设置了 float 的元素会脱离文档流。其根本缘由在于 float 的设计初衷是解决文字环绕图片的问题。你们要记住 float 的这个影响。orm
.clearfix:after { content: ''; display: table; clear: both; } .clearfix { *zoom: 1; /* 兼容 IE 低版本 */ } <div class="clearfix"> <img src="image/1.png" style="float: left"/> <img src="image/2.png" style="float: left"/> </div>
inline元素使用图片
text-align: center
block元素使用文档
margin: auto
绝对定位元素可结合left和margin实现,可是必须知道宽度。animation
.item { width: 300px; height: 100px; position: absolute; left: 50%; margin: -150px; }
inline 元素可设置line-height的值等于height值,如单行文字垂直居中:it
.container { height: 50px; line-height: 50px; }
绝对定位元素,可结合left和margin实现,可是必须知道尺寸。
.container { position: relative; height: 200px; } .item { width: 80px; height: 40px; position: absolute; left: 50%; top: 50%; margin-top: -20px; margin-left: -40px; }
绝对定位可结合transform实现居中。
.container { position: relative; height: 200px; } .item { width: 80px; height: 40px; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: blue; }
绝对定位结合margin: auto,不须要提早知道尺寸,兼容性好
.container { position: relative; height: 300px; } .item { width: 100px; height: 50px; position: absolute; left: 0; top: 0; right: 0; bottom: 0; margin: auto; }
首先,使用@keyframes定义一个动画,名称为testAnimation,以下代码,经过百分比来设置不一样的 CSS 样式,规定动画的变化。全部的动画变化均可以这么定义出来。
@keyframes myfirst { 0% {background: red; left:0; top:0;} 25% {background: yellow; left:200px; top:0;} 50% {background: blue; left:200px; top:200px;} 75% {background: green; left:0; top:200px;} 100% {background: red; left:0; top:0;} }
而后,针对一个 CSS 选择器来设置动画,例如针对div元素设置动画,以下:
div { width: 100px; height: 50px; position: absolute; animation-name: myfirst; animation-duration: 5s; }