站点: 前端开发文档
原文: CSS选择器
原文: CSS继承属性
原文: CSS3核心模块
原文: CSS盒子模型
原文: CSS背景图像
原文: CSS清除浮动
原文: CSS定位
并集:对选择器进行分组,被分组的选择器能够分享相同的声明。用逗号将须要分组的选择器开分。html
h1,h2,h3,h4,h5,h6{}
交集:两种属性同属一个元素前端
p.name{}
、p#id{}
、.name1.name2{}
后代(派生):根据元素在位置上的关系定义样式,使用空格隔开,后代选择器尽可能不要超过3个,没必要把每一个层级都列出,只须要写关键点便可node
li strong {}
子代:只能选择做为某元素的子元素,只选择子代,日后孙子一代不选择git
h1 > strong {}
兄弟和相邻兄弟:选择紧接在另外一元素后的,而且两者有相同父元素github
h1 + p {}
属性:对带有指定属性的HTML元素设置样式,权重为10web
title
属性的全部元素设置样式,[title] {}
title="name"
的全部元素设置样式,[title=name] {}
input[type="text"] {}
伪类:面试
:active
:被激活的元素:focus
:有键盘输入焦点的元素:hover
:鼠标悬停:link
:未被访问的连接:visited
:已被访问的连接:first-child
:元素的第一个子元素:lang
:带有指定lang
属性的元素权重:windows
div
(1)class/类选择器
(10)id
(100)结构选择器(新增伪类(面试题))浏览器
:not
:排除:nth-child(n)
:第几个元素 从1开始设置:nth-child(2n)
:偶数元素 从0开始设置:nth-child(2n+1)
:奇数元素:nth-of-type(n)
:某个元素下同类型的第几个元素:nth-last-child
:倒数第几个元素:first-child->:nth-child(1)
::fisrt-of-type
:第一个同级兄弟元素:last-of-type
:最后一个同级兄弟元素:nth-of-type(n)
:第几个同级兄弟元素:last-child
:最后一个子元素:only-child
:仅有一个子元素:only-of-type
:只有一个同类型的子元素:empty
:空内容:checked
:被选中 主要用在input
表单元素属性选择器frontend
E[attr=val]
:E[attr|=val]
:只能等于val
或只能以val-
开头E[attr*=val]
:包含val
字符串E[attr~=val]
:属性值有多个,其中一个是val
E[attr^=val]
:以val
开头E[attr$=val]
:以val
结尾目标伪类选择器
:target()
:用来匹配URL指向的目标元素(存在URL指向该匹配元素时,样式效果才会生效)伪元素:
:first-line
:匹配首行文本,只能用于块级元素:first-letter
:匹配首字符:before/:after
:DOM元素先后插入额外的内容
before/after
就要加上content=''
display: block;
:独占一行display: inline-block;
:不独占一行无继承性的属性
display
:规定元素应该生成的框的类型文本属性:
vertical-align
:垂直文本对齐text-decoration
:添加文本装饰text-shadow
:文本阴影效果white-space
:空白符的处理unicode-bidi
:设置文本的方向盒子模型的属性:
width
、height
margin
、margin-top/right/bottom/left
border
、border-top/right/bottom/left
border-style
、border-top/right/bottom/left-style
border-width
、border-top/right/bottom/left-width
border-color
、border-top/right/bottom/left-color
padding
、padding-top/right/bottom/left
背景属性:
background
background-color
background-image
background-repeat
background-position
background-attachment
定位属性:
float
clear
position
top/right/bottom/left
min-width/min-height
、max-width/max-height
overflow
clip
z-index
生成内容属性:
content
counter-reset
counter-increment
轮廓样式属性:
outline-style
outline-width
counter-color
outline
有继承性的属性
字体系列属性
font
:组合字体font-family
:字体系列font-weight
:字体粗细font-size
:字体尺寸font-style
:字体风格font-variant
:小写字母转换为大写,字体尺寸更小font-stretch
:对当前font-family
进行伸缩变形。全部主流浏览器不支持。font-size-adjust
:为某个元素规定一个aspect
值,保持首选字体的x-height
文本系列属性
text-indent
:文本缩进text-align
:文本水平对齐line-height
:行高word-spacing
:字间距letter-spacing
:字符间距text-transform
:控制文本大小写direction
:文本书写方向color
:文本颜色visibility
表格布局属性
caption-side
border-collapse
border-spacing
empty-cells
table-layout
列表布局属性
list-style-type
list-style-image
list-style-position
list-style
quotes
cursor
页面样式属性
page
page-break-inside
windows
orphans
过渡动画
transition
:过渡动画
transition-property
:过渡属性 all[attr]
transition-duration
:过渡时间transition-delay
:延迟时间transition-timing-function
:运行类型
ease
:(逐渐变慢)默认值linear
:匀速ease-in
:加速ease-out
:减速cubic-bezier
:贝塞尔曲线过渡动画效果思考步骤:
transition
属性2D变换
transform
:变形属性
rotate()
:旋转函数
deg
:度数transform-origin
:旋转的基点skew()
:倾斜函数
skewX()
skewY()
scale()
:缩放函数 默认值是1
scaleX()
scaleY()
translate()
:位移函数
translateX()
translateY()
animation-声明关键帧
关键帧——@keyframes
相似于flash
关键帧的时间单位
0%
、25%
、100%
等(设置某个时间段内任意时间点的样式)from(0%)
、to(100%)
:格式
@keyframes
:动画名称{动画状态}
animation-调用动画
必要属性
animation-name
:动画名称(关键帧名称)animation-duration
:动画执行时间可选属性:
animation-timing-function
linear
:匀速ease
:缓冲ease-in
:由慢到快ease-out
:由快到慢ease-in-out
:由慢到快再到慢ease-bezier(num,num,num,num)
:特定的贝塞尔曲线类型,4个数值需在[0,1]区间内animation-delay
:动画延迟animation-iteration-count
:重复次数animation-direction
:动画运行的方向 normal|reverse|alternate|alternate-reverse
animation-play-state
:动画状态 running|paused
animation-fill-mode
:动画结束后的状态 none|forwards|backwards|both
3D变换
transform-style: flat|preserve-3d
:3D空间展现perspective
:景深效果transform: persective(800px)
:直接做用在子元素上transform
:新增函数
translate3d(tx, ty, tz)
:translateX()
translateY()
translateZ()
rotate3d(rx, ry, rz, a)
:rotateX()
rotateY()
rotateZ()
scale3d(sx, sy, sz)
:sacleX()
sacleY()
sacleZ()
圆角 border-radius
border-radius
:1-4个数字/1-4个数字
没有/
则水平半径和垂直半径同样
border-radius: 10px/5px;
线性渐变 linear-gradient
linear-gradient
:([<起点>||<角度>,]?<点>,<点>...)参数
径向渐变 radial-gradient
radial-gradient
shape
形状:ellipse
、circle
或设置水平半径,垂直半径size
:渐变的大小,即渐变中止位置:
closet-side
:最左边farthest-side
:最远边closet-corner
:最近角farthest-corner
:最远角(默认值)position
:关键词|数值|百分比背景
background-origin
padding-box
:从padding
区域显示border-box
:从border
区域显示content-box
:从content
区域显示background-clip
padding-box
:从padding
区域向外裁剪border- box
:从border
区域向外裁剪content-box
:从content
区域向外裁剪text
:文本裁剪background-size
100% 100%
:百分比10px 10px
:数值contain
:按原始比例收缩,背景图显示完整,但不必定铺满整个容器cover
:按原比例收缩,背景图可能显示不完整,但铺满整个容器background-attachment
fixed
(固定的) 默认是滚动的盒子阴影
box-shadow
:h v blur spread color inset;
h
:水平方向偏移v
:垂直方向偏移blur
:模糊半径spread
:扩展半径color
:颜色inset
:内阴影,默认是外阴影文本阴影
text-shadow
:x y blur color
x
轴偏移 y
轴偏移 模糊度 颜色文字添加边框
text-stroke
:2px blue
1px
的透明边框,可让文字变得平滑滤镜
-webkit-filter:normal;
:正常-webkit-filter:grayscale(1);
:灰度,取值范围0-1-webkit-filter:brightness(0);
:亮度,取值范围0-1-webkit-filter:invert(1);
:反色,取值范围0-1,0为原图,1为完全反色-webkit-filter:sepia(0.5);
:叠加褐色,取值范围0-1-webkit-filter:hue-rotate(30deg);
:色相(按照色相环旋转,顺时针方向)(红-橙-黄-黄绿-绿-蓝绿-蓝-蓝紫-紫-紫红-红)此处为叠加黄色滤镜-webkit-filter:saturate(4);
:饱和度,取值范围0-*,0为无饱和度,1为原图,值越高,饱和度越大-webkit-filter:contrast(2);
:对比度,取值范围0-*,0为无对比度(灰色),1为原图,值越高对比度越大-webkit-filter:opacity(0.8);
:透明度,取值范围0-1,0为全透明,1为原图遮罩
mask-image
:mask-position
:mask-repeat
:border
边框
三角形箭头:
border
、border-width
、border-style
、border-color
三角形:
border
的3个属性:border-width/border-style/border-color
,宽度和高度都为0
,三角形箭头方向设定颜色,其他方向颜色设为透明transparent
margin
边距
margin
边距重叠: 取大值,不是二者相加之和。margin-top
的传递:大盒嵌套小盒,小盒加margin-top
值,传递到大盒,致使总体下移。
解决margin
的兼容性问题:
float: left;
overflow: hidden;
padding-top: 0/1px;
border-top: 1px solid transparent;
background
背景
主要属性:
background-color
:背景颜色,简写background
transparent
inherit
指定背景颜色,从父元素继承background-image
:背景图片
url
:图片URL地址node
:默认值 背景上未放置图片inherit
:指定背景图片从父元素继承一个元素能够引入多张背景图片;
background-image
放置在元素的左上角,并重复垂直和水平方向background-repeat
:背景重复
background-image
的垂直和水平方向repeat
默认repeat-x
只有水平位置重复repear-y
只有垂直位置重复no-repeat
不重复inherit
从父元素继承background-position
:背景定位
x
、y
水平位置,垂直位置。左上角是0
。单位(px,关键字,百分数)left right top bottom center
,仅指定一个关键字,其余值将会是center
x
轴方向,默认y
轴为center
inherit
从父元素继承background-attachment
:背景关联
scroll
默认fixed
固定inherit
从父元素继承background-size
:背景图像的尺寸大小
<length>
长度值指定图像大小。不容许负值<percentage>
百分比指定图像大小。不容许负值auto
图像的真实大小cover
将背景图像等比例缩放到彻底覆盖容器,有可能超出容器contain
等比例所放到宽/高与容器的宽/高相等,背景图像始终被包含在容器内background-origin
:设置背景图像的参考原点(位置)
padding-box
:从padding
区域(含padding
)开始显示背景border-box
:从border
区域(含border
)开始显示背景content-box
:从content
区域开始显示背景background-clip
:设置对象的背景图像向外裁剪的区域
padding-box
:从padding
区域(不含padding
)开始向外裁剪背景border-box
:从border
区域(不含border
)开始向外裁剪背景content-box
:从content
区域开始向外裁剪背景text
:从前景内容的形状(好比文字)做为裁剪区向外裁剪,实现使用背景做为填充色之类的遮罩效果。background-position: x y
overflow: hidden
overflow
溢出隐藏margin-top
的传递问题(面试题):
单行文本出现省略号(4个必备条件,缺一不可)
width
宽度(不写宽度,默认继承父元素宽度)overflow: hidden;
(溢出隐藏)white-space: nowrap;
text-overflow: ellipsis;
文字隐藏的方式,以省略号的方式隐藏多行文本出现省略号(必备条件,主要应用在移动端)
display: -webkit-box;
弹性盒模型-webkit-box-orient: vertical;
规定元素的排列方式:垂直排列-webkit-line-clamp: 2;
:文字的行数(自定义)overflow: hidden;
溢出隐藏多个元素在一行显示的方法
display: inline;
display: inline-block;
float: left/right;
display: inline-block;
元素的特色
verticle-align
属性会影响inline-block
元素,值可能会设为top
若是HTML源码中元素间有空格,列与列之间会产生空隙
解决方法:
dispay: inline-block;
,父元素增长一个属性font-size: 0;
,同时在元素自己增长font-size
属性进行覆盖display:inline-block;
在IE6/7下不兼容的解决方法
display: inline; zoom: 1;
属性IE7下块元素兼容display: inline-block;
写法?
display: inline;
),而后触发块元素的layout
(如:zoom: 1;
等)。div {display: inline-block; *display: inline; *zoom: 1;}
float
浮动float
元素的特色
left
时,浮动元素依次从父级盒子的左侧向右排列display: block;
文档流和脱离文档流
float
元素产生的影响
background-color
不起做用padding
不会被撑开border
不会被撑开float
清除浮动的方法
height
(不推荐)overflow: hidden;
;给最后一个浮动元素后面添加一个块级元素,这个块级元素带有clear: both;
属性
clear
清除浮动元素对文档流内元素的影响(可让文档流内的元素识别到浮动元素的高度)left
清除float
为left
的影响right
清除float
为right
的影响both
清除float
全部的影响inherit
从父级元素上继承该属性值clearfix
清除浮动(固定代码)
:after
清除浮动必备条件,缺一不可display: block;
确保元素是一个块级元素clear: both;
不容许左右两边有浮动对象content: '';
伪元素:brfore/:after
自带的属性,若是不写,伪元素不起做用height: 0;
防止在低版本浏览器中默认height: 1px;
的状况,用height: 0;
去覆盖font-size: 0;
字体大小overflow: hidden;
溢出隐藏visibility: hidden;
让全部可见性的元素隐藏overflow: hidden;
和visibility: hidden;
有什么区别?
(面试题):如何让一个元素消失?
opacity: 0;
[0-1] 透明度display: none;
隐藏widht/height/line-height + overflow
:宽/高/行高 + 溢出隐藏visibility: hidden;
让全部可见性的元素隐藏clear: both;
的特色
相对定位-position: relative;
top
和bottom
同时有值的状况下,top
值生效,支持负值left
和right
同时有值的状况下,left
值生效,支持负值绝对定位-position: absolute;
top
和bottom
同时有值,top
生效;left
和right
同时有值,left
生效。top
和bottom
同时设置值的状况下,会将这个盒子拉大,上下值都起做用,左右同理。z-index
属性,必需要和定位元素(绝对,相对,固定)同时使用,才会起做用。固定定位-position: fixed;
top/bottom/left/right
四个方位z-index
改变层级z-index
属性的特色
z-index
属性修改定位元素的层级关系z-index
默认值都同样z-index
值是数字没有单位,支持负数z-index
值,子元素的z-index
值进行比较