跳到主要内容

CSS 属性速查表

CSS 属性数量众多,且分布在不同的功能领域中。本文以"分类速查"的方式整理常用 CSS 属性,帮助你在实际开发中快速找到合适的属性。

文本与字体

属性说明常用值
color文本颜色#333, rgb(), hsl()
font-family字体族Arial, "Helvetica Neue"
font-size字体大小16px, 1rem, 1em
font-weight字体粗细normal, bold, 100-900
font-style字体样式normal, italic
line-height行高1.5, 24px, 150%
text-align文本对齐left, center, right, justify
text-decoration文本装饰none, underline, line-through
text-transform文本转换none, uppercase, lowercase
text-indent首行缩进2em, 20px
letter-spacing字符间距normal, 2px
word-spacing单词间距normal, 5px
white-space空白处理normal, nowrap, pre
text-overflow文本溢出clip, ellipsis

背景与边框

属性说明常用值
background-color背景颜色#fff, transparent
background-image背景图片url(), linear-gradient()
background-position背景位置center, top left, 50% 50%
background-size背景大小cover, contain, 100% 100%
background-repeat背景重复repeat, no-repeat
background-attachment背景附着scroll, fixed
border边框(简写)1px solid #ccc
border-width边框宽度1px, thin, medium
border-style边框样式solid, dashed, dotted
border-color边框颜色#ccc, transparent
border-radius圆角4px, 50%
box-shadow盒子阴影0 2px 4px rgba(0,0,0,0.1)
outline轮廓2px solid #007bff, none

盒模型与尺寸

属性说明常用值
width宽度100%, 300px, auto
height高度100%, 200px, auto
min-width最小宽度300px, 50%
max-width最大宽度1200px, 100%
min-height最小高度200px, 100vh
max-height最大高度600px, 100%
margin外边距20px, 10px 20px, auto
padding内边距20px, 10px 20px
box-sizing盒模型content-box, border-box

布局与定位

属性说明常用值
display显示方式block, inline, flex, grid
position定位方式static, relative, absolute, fixed
top顶部偏移0, 50%, 20px
right右侧偏移0, 50%, 20px
bottom底部偏移0, 50%, 20px
left左侧偏移0, 50%, 20px
z-index层叠顺序1, 100, auto
float浮动left, right, none
clear清除浮动left, right, both
overflow溢出处理visible, hidden, scroll, auto

Flexbox

属性说明常用值
flex-direction主轴方向row, column
flex-wrap换行nowrap, wrap
justify-content主轴对齐flex-start, center, space-between
align-items交叉轴对齐flex-start, center, stretch
align-content多行对齐flex-start, center, space-between
gap间距20px, 10px 20px
flex弹性(简写)1, 0 1 auto
flex-grow放大比例0, 1, 2
flex-shrink缩小比例1, 0
flex-basis基础大小auto, 200px, 0
order顺序0, 1, -1

Grid

属性说明常用值
grid-template-columns列定义1fr 1fr, repeat(3, 1fr)
grid-template-rows行定义100px 1fr, repeat(2, 1fr)
grid-template-areas区域定义"header header"
gap网格间距20px, 10px 20px
grid-column列位置1 / 3, span 2
grid-row行位置1 / 3, span 2
grid-area区域header, 1 / 1 / 3 / 3
justify-items项目列对齐start, center, stretch
align-items项目行对齐start, center, stretch

视觉效果

属性说明常用值
opacity透明度0, 0.5, 1
visibility可见性visible, hidden
filter滤镜blur(), brightness(), grayscale()
backdrop-filter背景滤镜blur(10px)
transform变换translate(), rotate(), scale()
transform-origin变换原点center, top left
transition过渡all 0.3s, transform 0.3s
animation动画fade 1s infinite
text-shadow文本阴影2px 2px 4px rgba(0,0,0,0.3)

交互与行为

属性说明常用值
cursor鼠标指针pointer, default, not-allowed
pointer-events指针事件auto, none
user-select用户选择none, text, all
resize调整大小none, both, vertical
scroll-behavior滚动行为auto, smooth

使用建议

  • 按分类查找:根据功能需求查找对应分类
  • 理解属性值:了解常用值的含义
  • 组合使用:多个属性配合实现效果
  • 参考文档:复杂属性查阅详细文档

这份速查表帮助你快速定位需要的属性,但深入学习仍需参考完整的教程内容。