一、CSS 选择符: 1.id选择器(# myid) 2.类选择器(.myclassname) ; 3.标签选择器(div, h1, p) ; 4.相邻选择器(h1 + p) ; 5.子选择器(ul > li) ; 6.后代选择器(li a) ; 7.通配符选择器( * ) ; 8.属性选择器(a[rel = “external”]) ; 9.伪类选择器(a: hover, li:nth-child); 10.CSS3新增伪类选择器 p:first-of-type 选择属于其父元素的首个 <p> 元素的每个 <p> 元素; p:last-of-type 选择属于其父元素的最后 <p> 元素的每个 <p> 元素; p:only-of-type 选择属于其父元素唯一的 <p> 元素的每个 <p> 元素; p:only-child 选择属于其父元素的唯一子元素的每个 <p> 元素; p:nth-child(2) 选择属于其父元素的第二个子元素的每个 <p> 元素; :enabled :disabled 控制表单控件的禁用状态; :checked 单选框或复选框被选中。 二、样式的继承 1、可继承的属性 1)、字体系列属性 font:组合字体; font-family:规定元素的字体系列; font-weight:设置字体的粗细; font-size:设置字体的尺寸; font-style:定义字体的风格; font-stretch:对当前的 font-family 进行伸缩变形。所有主流浏览器都不支持; font-size-adjust:为某个元素规定一个 aspect 值,这样就可以保持首选字体的 x-height。 2)、文本系列属性 text-indent:文本缩进; text-align:文本水平对齐; line-height:行高; word-spacing:增加或减少单词间的空白(即字间隔); letter-spacing:增加或减少字符间的空白(字符间距); text-transform:控制文本大小写; direction:规定文本的书写方向; color:文本颜色。 3)、元素可见性:visibility;; 4)、表格布局属性:caption-side、border-collapse、border-spacing、empty-cells、table-layout; 5)、列表布局属性:list-style-type、list-style-image、list-style-position、list-style; 6)、生成内容属性:quotes; 7)、光标属性:cursor; 8)、页面样式属性:page、page-break-inside、windows、orphans; 2、不可继承的样式: 1)、display:规定元素应该生成的框的类型; 2)、文本属性 vertical-align:垂直文本对齐; text-decoration:规定添加到文本的装饰; text-shadow:文本阴影效果; white-space:空白符的处理; unicode-bidi:设置文本的方向。 3)、盒子模型的属性:width、height、margin 、margin-top、margin-right、margin-bottom、margin-left、border、border-styl e、border-top-style、border-right-style、border-bottom-style、border-left-style、border-width、border-top-width、border-rig ht-right、border-bottom-width、border-left-width、border-color、border-top-color、border-right-color、border-bottom-color、 border-left-color、border-top、border-right、border-bottom、border-left、padding、padding-top、padding-right、padding-bo ttom、padding-left; 4)、背景属性:background、background-color、background-image、background-repeat、background-position、background- attachment; 5)、定位属性:float、clear、position、top、right、bottom、left、min-width、min-height、max-width、max-height、overflow、 clip、z-index; 6)、生成内容属性:content、counter-reset、counter-increment; 7)、轮廓样式属性:outline-style、outline-width、outline-color、outline; 8)、页面样式属性:size、page-break-before、page-break-after; 9)、声音样式属性:pause-before、pause-after、pause、cue-before、cue-after、cue、play-during。 三、优先级算法: 1.优先级就近原则,同权重情况下样式定义最近者为准; 2.载入样式以最后载入的定位为准; 3.!important > id > class > tag ; 4.important 比内联优先级高,但内联比 id 要高。 *注:直接数就行(只要选择同一个元素,优先级div.box > .box) 四、CSS3新增样式
- CSS3实现圆角(border-radius),阴影(box-shadow);
- 对文字加特效(text-shadow、),线性渐变(gradient),旋转(transform);
- transform:rotate(9deg) scale(0.85,0.90) translate(0px,-30px) skew(-9deg,0deg);// 旋转,缩放,定位,倾斜;
- 增加了更多的CSS选择器 多背景 rgba;
- 在CSS3中唯一引入的伪元素是 ::selection.
- 媒体查询,多栏布局;
- border-image。
五、display的样式
有很多:none | inline | block | inline-block | list-item | run-in | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-colume-group | table-column | table-cell | table-caption | inherit 下面只列举些常用的值。 inline(默认值)
1.内容撑开宽度。
2.对它进行设置宽高度是无效的。
3.不单独占一行,其他元素会紧跟其后。
4.如果对inline元素设置float及position:absolute/fixed,会发现元素被“块”化,可以对其设置宽高了。
block
1.可以设置宽高。
2.单独占一行。
3.宽度不设置的话,宽度为父元素的宽度。 inline-block
可以理解为既有inline的同行特性也有block的宽高特性。可以想想一般的button、input是什么样子的。
1.不单独占一行。
2.可以设置宽高。
none
1.隐藏元素并脱离文档流。
2.和visibility的区别就在于,visibility:hidden还会保留元素本该显示的空间。但none不会。
inherit
继承父元素的display属性的值。
table
也是一个“块”,但和block相比,它具有包裹性。
六、position区别 1.absolute 生成绝对定位的元素,absolute的”根元素“是可以设置的,绝对定位的元素的位置相对于最近的已定位祖先元素,如果元素没有已定位的祖先元素,那么它的位置相对于最初的包含块。
2.fixed 生成绝对定位的元素,相对于浏览器窗口进行定位(老IE不支持)。
3.relative 生成相对定位的元素,相对于其在普通流中的位置进行定位。
4.static 默认值。没有定位,元素出现在正常的流中(忽略 top, bottom, left, right z-index 声明)。
5.inherit 规定从父元素继承 position 属性的值。
文章仅作为分享
地址https://blog.csdn.net/linxner/article/details/80761125
|