120+ 属性 · 可打印
前端Wiki/工具/CSS 速查表

CSS 速查表

本页收录日常开发高频使用的 125 个 CSS 属性与选择器,按选择器、盒模型、Flexbox/Grid 布局、定位、文本字体、背景边框、过渡动画、变形、单位函数、媒体查询、伪类伪元素等 12 个分类组织,每项附语法、说明与代码示例,适合打印贴墙或日常速查。

选择器 8 项

属性 / 选择器语法说明示例
* / 元素 / .类 / #ID*通用选择器匹配所有元素;元素选择器如 p;.box 匹配 class;#box 匹配 id*{margin:0} p{line-height:1.6} .box{} #header{}
属性选择器[attr] [attr=v] [attr^=v] [attr$=v] [attr*=v]匹配含有某属性、等于、以 v 开头、结尾或包含 v 的元素a[href^="https"]{color:#2f81f7}
后代 / 子代选择器A B / A > B空格为后代(任意层级);> 为直接子元素nav a{} ul > li{}
相邻 / 通用兄弟A + B / A ~ B+ 紧邻的下一个兄弟;~ 后面所有同级兄弟h1 + p{} .item ~ .item{}
分组选择器A, B逗号分组,共享同一规则块h1,h2,h3{font-weight:700}
:is() :where() :where():is(a,b) :where(a,b)匹配列表中任一选择器;:where() 优先级恒为 0,:is() 取列表最高:is(h1,h2){} :where(.a,.b){}
:has()A:has(B)父选择器:匹配包含指定后代的 Adiv:has(> img){padding:0}
*组合 与 优先级选择器组合优先级:内联 > ID > 类/属性/伪类 > 元素/伪元素;同权重按书写顺序层叠#nav .link:hover{color:red}

盒模型 12 项

属性 / 选择器语法说明示例
width / heightwidth: <长度|%|auto>设置内容区宽高;auto 由内容或父级决定width:120px; height:80px
min-width / max-widthmin-width: <长度|%>限制元素的最小/最大尺寸,常用于响应式防挤压max-width:960px
box-sizingcontent-box | border-boxborder-box 让 width 包含 padding 与 border,布局更可控*,*::before,*::after{box-sizing:border-box}
marginmargin: <上> <右> <下> <左>外边距;auto 可实现块级水平居中;相邻 margin 会折叠margin:0 auto; margin-bottom:16px
paddingpadding: <上右下左>内边距,撑大元素内部留白,不含负值padding:12px 16px
borderborder: <宽> <样式> <颜色>简写边框;样式有 solid/dashed/dotted/double/noneborder:1px solid #2d3748
border-radiusborder-radius: <半径>圆角;写四个值对应左上/右上/右下/左下;50% 为圆形border-radius:8px; border-radius:50%
outlineoutline: <宽> <样式> <颜色>描边,不占布局空间,常用于无障碍聚焦态:focus-visible{outline:2px solid #4a9eff}
box-shadowbox-shadow: x y 模糊 扩散 颜色 inset投影;逗号可叠加多层阴影box-shadow:0 4px 12px rgba(0,0,0,.3)
overflowvisible | hidden | auto | scroll内容溢出处理;overflow-x / overflow-y 分轴控制overflow:auto
displayblock | inline | flex | grid | none决定元素的显示模式与布局上下文display:flex
visibilityvisible | hidden | collapse隐藏元素但保留占位;display:none 不保留visibility:hidden

布局 · Flexbox 11 项

属性 / 选择器语法说明示例
flex-directionrow | row-reverse | column | column-reverse主轴方向;row 为默认水平flex-direction:column
flex-wrapnowrap | wrap | wrap-reverse是否换行;nowrap 默认强制单行可能溢出flex-wrap:wrap
flex-flowflex-flow: <direction> <wrap>direction 与 wrap 的简写flex-flow:row wrap
justify-contentflex-start | center | flex-end | space-between | space-around | space-evenly主轴对齐与间距分布justify-content:center
align-itemsstretch | flex-start | center | flex-end | baseline交叉轴对齐方式align-items:center
align-contentflex-start | center | stretch | space-between多行时交叉轴整体对齐align-content:space-between
align-selfauto | flex-start | center | ...覆盖父级 align-items,单个项目对齐.item{align-self:flex-end}
flexflex: <grow> <shrink> <basis>flex:1 表示剩余空间等比分配.main{flex:1}
flex-grow / flex-shrinkflex-grow: <数字>剩余空间放大比例 / 空间不足收缩比例flex-grow:2
gapgap: <行间距 列间距>Flex/Grid 项目间距,替代 margin 方案gap:12px 8px
orderorder: <整数>调整项目排列顺序,默认 0;越小越靠前order:-1

布局 · Grid 10 项

属性 / 选择器语法说明示例
grid-template-columnsgrid-template-columns: <轨道列表>定义列轨道;repeat() 与 fr 单位常用grid-template-columns:repeat(3,1fr)
grid-template-rowsgrid-template-rows: <轨道列表>定义行轨道grid-template-rows:auto 1fr
grid-template-areasgrid-template-areas: "a b"命名网格区域,配合 grid-area 使用grid-template-areas:"hd hd" "sd mn"
grid-areagrid-area: <区域名>把项目放到命名区域.hd{grid-area:hd}
grid-column / grid-rowgrid-column: <起>/<止>跨列/跨行:起止线编号,span n 表示跨 n 格grid-column:1/3 或 span 2
gap / column-gapgap: <行 列>网格行列间距,同 Flexgap:16px
justify-items / align-itemsstart | center | end | stretch单元格内容在各自格内的对齐justify-items:center
place-itemsplace-items: <align> <justify>align-items 与 justify-items 简写place-items:center
justify-content (grid)start | center | space-between整个网格在容器内的主轴对齐(轨道小于容器时)justify-content:center
grid-auto-flowrow | column | dense隐式项目的排列方向;dense 启用密集填充grid-auto-flow:dense

布局 · 定位 7 项

属性 / 选择器语法说明示例
positionstatic | relative | absolute | fixed | stickyrelative 相对自身;absolute 相对最近定位祖先;fixed 相对视口;sticky 滚动吸附position:sticky; top:0
top / right / bottom / lefttop: <长度|%|auto>配合非 static 定位使用,设置偏移量position:absolute; top:10px; left:20px
z-indexz-index: <整数>层叠顺序,仅对定位元素生效;需在同一层叠上下文中比较z-index:100
insetinset: <上 右 下 左>top/right/bottom/left 简写inset:0
floatleft | right | none元素浮动,文本可环绕;现代布局多用 Flex/Grid 替代float:left
clearleft | right | both清除浮动影响clear:both
object-fitfill | contain | cover | none替换元素(img/video)内容如何填充盒子img{width:100%; object-fit:cover}

文本与字体 16 项

属性 / 选择器语法说明示例
font-familyfont-family: <字体栈>字体回落栈,含中文字体与英文等宽字体font-family:var(--mono)
font-sizefont-size: <长度>字号;建议使用 rem 单位做缩放font-size:14px
font-weightnormal | bold | 100-900字重;400=normal,700=bold;可变字体支持任意值font-weight:600
font-stylenormal | italic | oblique字体样式:斜体font-style:italic
line-heightline-height: <数字|长度>行高;无单位数字按字号倍数继承line-height:1.75
letter-spacingletter-spacing: <长度>字符间距letter-spacing:.05em
word-spacingword-spacing: <长度>单词间距(对英文有效)word-spacing:2px
text-alignleft | center | right | justify文本水平对齐text-align:center
vertical-alignbaseline | top | middle | bottom行内元素与表格单元格垂直对齐vertical-align:middle
text-decorationtext-decoration: <line> <style> <color>下划线/删除线;none 常用于去除链接默认样式text-decoration:none
text-indenttext-indent: <长度>首行缩进text-indent:2em
text-overflowclip | ellipsis配合 overflow:hidden 与 white-space:nowrap 实现单行省略号white-space:nowrap; overflow:hidden; text-overflow:ellipsis
text-transformnone | uppercase | lowercase | capitalize文本大小写转换text-transform:uppercase
white-spacenormal | nowrap | pre | pre-wrap空白与换行处理;pre-wrap 保留换行且自动折行white-space:pre-wrap
word-breaknormal | break-all | keep-all长单词/URL 换行规则;break-all 强制断行word-break:break-all
colorcolor: <颜色值>文本颜色;支持 命名颜色/HEX/rgb()/hsl()/currentcolorcolor:var(--text2)

背景与边框 10 项

属性 / 选择器语法说明示例
backgroundbackground: <color> <image> <repeat> <position>/<size>简写,可同时定义多层背景background:#fff url(bg.png) no-repeat center/cover
background-colorbackground-color: <颜色>背景色background-color:#161b22
background-imagebackground-image: url(...) | linear-gradient() | radial-gradient()背景图或渐变,逗号叠加多层background-image:linear-gradient(#2f81f7,#a371f7)
background-sizeauto | cover | contain | <长度>cover 填满裁切,contain 完整留白background-size:cover
background-position<关键字> | <坐标>背景图位置background-position:center top
background-repeatrepeat | no-repeat | repeat-x | repeat-y背景平铺方式background-repeat:no-repeat
background-clipborder-box | padding-box | content-box背景绘制范围;text 可做文字渐变background-clip:text
background-attachmentscroll | fixed | local背景随滚动固定的视差效果background-attachment:fixed
border-stylenone | solid | dashed | dotted | double边框样式,必填项才能显示边框border-style:solid
border-collapsecollapse | separate表格边框合并table{border-collapse:collapse}

过渡与动画 11 项

属性 / 选择器语法说明示例
transitiontransition: <属性> <时长> <缓动> <延迟>状态变化的补间动画;all 表示全部属性transition:all .25s ease
transition-propertytransition-property: <属性列表>指定参与过渡的属性transition-property:color,background
transition-durationtransition-duration: <时间>过渡时长,如 .3stransition-duration:.3s
transition-timing-functionlinear | ease | ease-in-out | cubic-bezier() | steps()缓动曲线transition-timing-function:cubic-bezier(.4,0,.2,1)
transition-delaytransition-delay: <时间>延迟开始过渡transition-delay:.1s
@keyframes@keyframes <name> { from{} to{} }定义关键帧动画@keyframes spin{to{transform:rotate(360deg)}}
animationanimation: <name> <时长> <缓动> <次数> <填充>动画简写animation:spin 1s linear infinite
animation-iteration-count<整数> | infinite动画播放次数animation-iteration-count:infinite
animation-directionnormal | reverse | alternate播放方向;alternate 交替往返animation-direction:alternate
animation-fill-modenone | forwards | backwards | both动画停留/起始帧状态;forwards 停在最后一帧animation-fill-mode:forwards
animation-play-staterunning | paused控制动画播放与暂停animation-play-state:paused

变形 Transform 8 项

属性 / 选择器语法说明示例
transformtransform: <函数列表>对元素变形:平移/旋转/缩放/倾斜,不影响布局transform:translate(-50%,-50%)
translate()translate(x, y) | translateX/Y/Z()平移;百分比相对元素自身,常用于绝对定位居中left:50%; transform:translateX(-50%)
rotate()rotate(<角度>) | rotateX/Y/Z()旋转,单位 deg;3D 需配合 perspectivetransform:rotate(45deg)
scale()scale(x, y) | scaleX/Y()缩放,1 为原始大小;会让文本模糊时谨慎使用transform:scale(1.1)
skew()skew(xDeg, yDeg)倾斜transform:skew(10deg,0)
transform-origintransform-origin: <x> <y>变形基点,默认 50% 50%transform-origin:top left
perspectiveperspective: <长度>3D 透视距离,开启子元素 3D 空间perspective:800px
will-changewill-change: transform | opacity提前告知浏览器将变化的属性以优化合成层(避免滥用)will-change:transform

单位与函数 10 项

属性 / 选择器语法说明示例
px / %绝对 / 相对百分比px 固定像素;% 相对父级(背景图相对元素盒)width:50%
em / rem相对字号单位em 相对父级字号会叠加,rem 相对根字号,推荐用 remfont-size:1.2rem
vw / vh / vmin视口单位1vw = 视口宽度的 1%;vmin 取较小边,适合移动端height:100vh
dvh / svh / lvh动态视口高度移动端随浏览器工具栏伸缩的视口高度,替代 100vh 滚动溢出问题height:100dvh
calc()calc(表达式)混合不同单位做计算,运算符两侧需留空格width:calc(100% - 40px)
min() / max()min(a, b) / max(a, b)取较小/较大值,多用于响应式钳制font-size:min(16px,4vw)
clamp()clamp(最小, 首选, 最大)把值钳制在区间内,流式排版利器font-size:clamp(14px,2.5vw,18px)
var()var(--name, <fallback>)使用自定义属性(CSS 变量),支持运行时切换主题color:var(--text,#e6edf3)
color-mix()color-mix(in srgb, a p%, b)按比例混合两种颜色border:1px solid color-mix(in srgb,#fff 20%,transparent)
fit-content / minmax()grid 轨道函数minmax(200px,1fr) 限制轨道范围;fit-content 按内容收缩grid-template-columns:minmax(200px,1fr)

媒体查询与响应式 8 项

属性 / 选择器语法说明示例
@media@media <条件> { ... }按视口宽度/媒体特性应用样式,响应式核心@media (max-width:768px){.wrap{padding:12px}}
@container@container <名称> (条件)容器查询:按父容器而非视口响应@container (min-width:400px){.card{flex-direction:row}}
prefers-color-scheme@media (prefers-color-scheme: dark)跟随系统暗色模式@media (prefers-color-scheme:dark){:root{--bg:#0d1117}}
prefers-reduced-motion@media (prefers-reduced-motion: reduce)尊重用户「减少动效」偏好@media (prefers-reduced-motion:reduce){*{transition:none}}
pointer / hover@media (hover: hover) (pointer: fine)区分为触屏/鼠标设备,做交互降级@media (hover:hover){.card:hover{transform:translateY(-3px)}}
@supports@supports (条件)特性检测,渐进增强@supports (display:grid){.list{display:grid}}
aspect-ratioaspect-ratio: <宽>/<高>固定宽高比,用于视频/图片占位防布局抖动aspect-ratio:16/9
orientation@media (orientation: landscape)横屏/竖屏判断@media (orientation:portrait){.nav{flex-direction:column}}

伪类与伪元素 14 项

属性 / 选择器语法说明示例
:hovera:hover鼠标悬停状态a:hover{text-decoration:underline}
:focus / :focus-visibleinput:focus聚焦态;:focus-visible 仅键盘聚焦显示,鼠标点击不显示input:focus-visible{border-color:#2f81f7}
:nth-child():nth-child(n | 2n | odd | even)按位置匹配子元素;2n=偶数,odd=奇数li:nth-child(odd){background:#161b22}
:first-child / :last-childE:first-child匹配父级第一个/最后一个子元素li:first-child{border-top:none}
:nth-of-type():nth-of-type(2n)在同类型兄弟中计数p:nth-of-type(2){color:#9aa7b8}
:not()E:not(<选择器>)排除匹配元素a:not([href]){color:#6e7b8d}
:checkedinput:checked + label表单选中态(radio/checkbox)input:checked + label{color:#2f81f7}
:disabledbutton:disabled禁用态表单控件button:disabled{opacity:.5; cursor:not-allowed}
:emptyE:empty匹配无子节点的元素div:empty{display:none}
::before / ::afterE::before{content:...}生成内容伪元素,content 不可省.tag::before{content:"#"}
::selection::selection文本选中高亮::selection{background:#2f81f7; color:#fff}
::placeholderinput::placeholder输入框占位符样式input::placeholder{color:#6e7b8d}
::markerli::marker列表符号样式li::marker{color:#4a9eff}
*层叠与继承控制继承与层叠all:initial 重置全部;inherit 强制继承;unset 按默认;!important 提权重*{all:unset} a{color:inherit !important}
回到 前端Wiki 首页 · 更多工具见 前端开发工具箱