CSS 属性列表(含常用取值说明)

260 阅读9分钟

✅ 本列表覆盖 CSS1/2/3 主流属性,按功能分类,包含 属性名、说明、常用取值及取值解释
📚 数据来源:W3C 标准 & MDN Web Docs(截至 2025 年)


一、布局与定位(Layout & Positioning)

属性说明常用取值及解释
position定义元素的定位方式static:默认,文档流中正常排列 relative:相对自身原位置偏移 absolute:脱离文档流,相对于最近定位祖先定位 fixed:相对于视口固定定位 sticky:在滚动到特定阈值时变为 fixed
top定位元素距包含块顶部的距离长度值(10px, 2em)、百分比(5%)、auto
right距右边缘距离top
bottom距底边缘距离top
left距左边缘距离top
z-index控制层叠顺序整数(1, -1, 999),数值越大越在上层;仅对定位元素有效
display元素显示类型block:块级,独占一行 inline:行内,不独占行 inline-block:行内块,可设宽高 flex:弹性容器 grid:网格容器 none:隐藏且不占空间
float浮动方向left:向左浮动 right:向右浮动 none:不浮动(默认)
clear清除浮动影响left/right/both:不允许左侧/右侧/两侧有浮动元素 none:无清除
visibility是否可见visible:可见 hidden:隐藏但占空间 collapse:表格中行/列折叠
overflow溢出处理方式visible:溢出可见(默认) hidden:裁剪溢出 scroll:始终显示滚动条 auto:需要时显示滚动条
overflow-x水平溢出处理overflow
overflow-y垂直溢出处理overflow
clip-path裁剪元素可视区域inset(), circle(), ellipse(), polygon(), url()none
contain渲染性能优化提示layout:布局独立 paint:绘制独立 strict:完全隔离(提升性能)

二、盒模型(Box Model)

属性说明常用取值及解释
width内容宽度长度、百分比、autofit-contentmax-content
min-width最小宽度防止内容过窄,常用于响应式
max-width最大宽度限制宽度,避免过宽(如图片)
height内容高度width
min-height最小高度常用于防止容器塌陷
max-height最大高度限制高度,配合 overflow 使用
margin外边距(简写)10px, 1em, auto(居中常用) 可写 1~4 个值(上右下左)
margin-top单边外边距margin
padding内边距(简写)margin,控制内容与边框距离
padding-top单边内边距padding
box-sizing盒模型计算方式content-box:宽高仅含内容(默认) border-box:宽高包含 padding 和 border(推荐)
border边框简写1px solid #000 = width style color
border-width边框宽度1px, thin, medium, thick
border-style边框样式solid:实线 dashed:虚线 dotted:点线 double:双线 none:无边框
border-color边框颜色颜色值(#fff, red, rgba()
border-radius圆角半径5px, 50%(圆形),可设两个值(水平/垂直)
border-top-left-radius单角圆角分别设置四个角的圆角大小

三、背景与边框(Backgrounds & Borders)

属性说明常用取值及解释
background背景简写color image repeat position/size attachment
background-color背景色颜色值,transparent 表示透明
background-image背景图像url("img.jpg"), linear-gradient(...), none
background-repeat背景重复repeat:平铺 no-repeat:不重复 repeat-x/repeat-y:单向重复
background-attachment背景滚动行为scroll:随内容滚动(默认) fixed:固定背景(视差滚动) local:随内容滚动,但受 overflow 影响
background-position背景位置center, top left, 50% 50%, 10px 20px
background-size背景尺寸cover:覆盖全区域(可能裁剪) contain:完整显示(可能留白) 100% 100%:拉伸填充
background-clip背景绘制区域border-box:绘制到边框 padding-box:不绘制边框区域 content-box:仅内容区 text:仅文字内部(配合 -webkit-text-fill-color: transparent
background-origin背景定位起点padding-box(默认) border-box content-box
border-image图像边框简写source slice width outset repeat
border-image-source图像源url(), gradient, none
border-image-slice切片方式30%, fill(保留中间内容)
border-image-width图像边框宽度长度、百分比、倍数
border-image-outset边框超出容器距离长度值
border-image-repeat图像平铺方式stretch, repeat, round, space

四、文本与字体(Text & Fonts)

属性说明常用取值及解释
color文本颜色颜色值(#000, rgb(), hsl(), transparent
font字体简写style weight size/line-height family
font-family字体族"Arial", "Microsoft YaHei", sans-serif(通用族)
font-size字号16px, 1em, 1rem, small, large
font-weight字重normal(400), bold(700), 100-900
font-style字体风格normal, italic(斜体), oblique(倾斜)
line-height行高数字(1.5)、长度、百分比;常用于垂直居中文本
text-align文本对齐left, right, center, justify(两端对齐)
vertical-align垂直对齐top, middle, bottom, baseline(默认)
text-decoration装饰线none, underline, overline, line-through
text-indent首行缩进2em 常用于段落开头
text-overflow文本溢出显示clip:直接裁剪 ellipsis:显示省略号(需配合 white-space: nowrapoverflow: hidden
white-space空白处理normal:合并空白 nowrap:不换行 pre:保留空白和换行 pre-wrap:保留空白,允许换行 pre-line:合并空格,保留换行
word-spacing字间距2px, 0.1em
letter-spacing字符间距1px, 0.05em
word-break单词断行normal, break-all(强制断中文/英文), keep-all(仅断空格)
overflow-wrap / word-wrap长单词换行normal, break-word(允许长单词换行)
text-shadow文本阴影h-offset v-offset blur color,如 2px 2px 4px rgba(0,0,0,0.5)
text-transform文本转换uppercase, lowercase, capitalize(首字母大写), none
direction文本方向ltr(左到右), rtl(右到左,用于阿拉伯语等)
unicode-bidi双向文本控制通常与 direction 配合使用,如 bidi-override

五、弹性布局(Flexbox)

属性说明常用取值及解释
flex-direction主轴方向row(左→右), row-reverse, column(上→下), column-reverse
flex-wrap是否换行nowrap(默认), wrap, wrap-reverse
justify-content主轴对齐flex-start, flex-end, center, space-between, space-around, space-evenly
align-items交叉轴对齐flex-start, flex-end, center, baseline, stretch(拉伸填满)
align-content多行对齐flex-start, center, space-between 等(仅多行有效)
flex-grow放大比例0(不放大), 1(等分剩余空间)
flex-shrink缩小比例1(可缩小), 0(禁止缩小)
flex-basis初始主轴尺寸auto, 200px, 10em
flex三者简写flex: 1 = 1 1 0 flex: 0 1 auto(默认)
order排列顺序整数,数值越小越靠前
align-self单项目对齐覆盖 align-items,取值相同

六、网格布局(Grid Layout)

属性说明常用取值及解释
grid-template-columns定义列100px 1fr, repeat(3, 1fr), minmax(100px, 1fr)
grid-template-rows定义行同上
grid-template-areas命名区域布局"header header" "nav main" "footer footer"
grid-auto-columns隐式列大小自动创建的列的默认尺寸
grid-auto-rows隐式行大小同上
grid-auto-flow自动填充方向row(先行后列), column, dense(致密填充)
gap网格间距10px, 1em 2em(行 1em,列 2em)
grid-column-start起始列线1, span 2, end
grid-column-end结束列线同上
grid-column列简写1 / 3span 2
grid-row-start起始行线同列
grid-row-end结束行线同列
grid-row行简写grid-column
grid-area区域命名或定位header, 1 / 1 / 3 / 2(行起/列起/行止/列止)

七、变换、过渡与动画

✅ 变换(Transform)

属性说明常用取值及解释
transform应用变换translate(10px, 5px) rotate(45deg) scale(1.2) skew(10deg) 可组合:translateX(10px) rotate(30deg)
transform-origin变换中心点center, top left, 50% 50%, 10px 20px
transform-style子元素 3D 空间flat(扁平), preserve-3d(保留 3D)
perspective3D 透视距离500px, 1000px(值越小透视感越强)
perspective-origin透视原点transform-origin
backface-visibility背面是否可见visible, hidden(翻转时隐藏背面)

✅ 过渡(Transition)

属性说明常用取值及解释
transition过渡简写property duration timing-function delay 例:all 0.3s ease-in-out 0.1s
transition-property参与过渡的属性width, opacity, transform, all
transition-duration持续时间0.2s, 500ms
transition-timing-function缓动函数ease, linear, ease-in, ease-out, cubic-bezier(0.42, 0, 0.58, 1)
transition-delay延迟时间0.1s, 500ms

✅ 动画(Animation)

属性说明常用取值及解释
animation动画简写name duration timing-function delay iteration-direction fill-mode play-state
animation-name@keyframes 名称fade, slideIn, spin
animation-duration动画时长1s, 300ms
animation-timing-function缓动函数transition-timing-function
animation-delay延迟启动0.5s
animation-iteration-count播放次数1, infinite(无限循环)
animation-direction播放方向normal, reverse, alternate(来回播放), alternate-reverse
animation-play-state播放状态running, paused(可用于悬停暂停)
animation-fill-mode动画外状态none, forwards(停在最后一帧), backwards, both

八、滤镜与视觉效果

属性说明常用取值及解释
filter视觉滤镜blur(2px), brightness(1.2), contrast(150%), drop-shadow(2px 2px 4px black) grayscale(100%), hue-rotate(90deg), invert(1)
backdrop-filter背景滤镜blur(10px) 实现毛玻璃效果,常用于模态框、导航栏

九、用户界面

属性说明常用取值及解释
cursor鼠标样式pointer(手型), move, not-allowed, zoom-in, text, wait
resize是否可调整大小none, both, horizontal, vertical(常用于 textarea)
user-select是否可选中文本none(禁止选择), text, all, auto
pointer-events是否响应鼠标事件auto(正常), none(穿透点击)
caret-color输入光标颜色red, #00ff00, transparent

十、多列布局

属性说明常用取值及解释
columns列数与宽度3 200px = 3列,每列约200px
column-count列数2, 3
column-width每列宽度150px, auto
column-gap列间距20px, 1em
column-rule列间线1px solid #ddd
column-span跨列none, all(如标题跨所有列)

十一、其他重要属性

属性说明常用取值及解释
aspect-ratio宽高比16 / 9, 1 / 1(保持比例,响应式推荐)
--*自定义属性(CSS 变量)--main-color: #007bff;,使用 var(--main-color)
env()环境变量env(safe-area-inset-top) 用于适配 iPhone 刘海屏

使用建议

  • 初学者重点掌握:盒模型、文本、display、position、flex、transition、transform
  • 响应式设计必学:flex、grid、media queries、aspect-ratio
  • 动效设计必学:transition + transform、animation、keyframes