常用 CSS 样式速查表,涵盖了现代 Web 开发中最核心的样式属性与常用值,适合作为日常开发参考。


1. 盒模型与尺寸

属性说明常用值
width / height宽高auto100%50px50vwcalc(100% - 20px)
max-width / min-width最大/最小宽度100%800px
margin外边距0 auto(水平居中), 10px5%
padding内边距10px1em5%
box-sizing盒模型计算方式border-box(推荐), content-box
overflow溢出处理hiddenautoscroll
aspect-ratio宽高比16/91/1

2. 布局方式

常规显示模式(display)

说明
block块级元素,独占一行
inline行内元素,宽度随内容
inline-block行内块,可设宽高且不换行
none隐藏元素(不占位)
flex弹性盒布局
grid网格布局

定位(position)

属性说明常用值
position定位方式relativeabsolutefixedsticky
top / right / bottom / left偏移量010px50%
z-index层叠顺序1100auto

Flex 布局

属性(容器)常用值
flex-directionrowcolumnrow-reverse
justify-contentcenterspace-betweenspace-aroundflex-startflex-end
align-itemscenterstretchflex-startflex-end
flex-wrapwrapnowrap
gap10px1rem
属性(项目)常用值
flex1(占满剩余空间), auto
order-11(调整顺序)
align-selfcenterflex-end

Grid 布局

属性(容器)常用值
grid-template-columnsrepeat(3,1fr)200px 1frauto
grid-template-rows100px auto
gap10px
justify-items / align-itemscenterstretch
属性(项目)常用值
grid-columnspan 21/3
grid-rowspan 2

浮动与清除(现代布局已少用,但需了解)

属性说明常用值
float浮动leftright
clear清除浮动bothleftright

3. 文本样式

属性说明常用值
color文字颜色#333rgb(0,0,0)red
font-family字体族"PingFang SC", "Microsoft YaHei", sans-serif
font-size字号16px1rem1.2em
font-weight字重normalbold400700
line-height行高1.524px150%
text-align水平对齐leftcenterrightjustify
text-decoration文本装饰noneunderlineline-through
text-transform大小写转换uppercaselowercasecapitalize
letter-spacing字间距1px0.1em
word-break换行规则break-allkeep-allbreak-word
white-space空白处理nowrappre-wrapnormal
text-overflow溢出省略号ellipsis(常配合 overflow:hidden + white-space:nowrap
vertical-align垂直对齐(行内/表格)middletopbottom

实用文本截断

css

/* 单行省略 */.ellipsis {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;}/* 多行省略(WebKit) */.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;}


4. 背景与渐变

属性说明常用值
background-color背景颜色#f0f0f0rgba(0,0,0,0.5)
background-image背景图片/渐变url('...')linear-gradient(...)
background-size尺寸covercontain100% auto
background-position位置centertop left50% 50%
background-repeat重复no-repeatrepeat-x
background-attachment滚动行为fixedscroll
background 简写一次设置多个#fff url('...') no-repeat center/cover

渐变示例

css

/* 线性渐变 */background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);/* 径向渐变 */background: radial-gradient(circle at center, #ff9a9e, #fad0c4);


5. 边框与阴影

属性说明常用值
border边框简写1px solid #cccnone
border-radius圆角4px50%(圆形), 8px 0 8px 0
box-shadow盒阴影0 2px 8px rgba(0,0,0,0.1)(外阴影)
inset 0 0 5px #ccc(内阴影)
outline轮廓(不占位)2px solid rednone
outline-offset轮廓偏移2px

6. 变换与过渡动画

Transform(2D/3D变换)

属性常用值
transformtranslate(10px, 50%) / rotate(45deg) / scale(1.2) / skew(10deg)
transform-origincentertop left

Transition(过渡)

css

transition: all 0.3s ease;/* 分别指定:属性  时长  缓动  延迟 */transition: opacity 0.2s linear 0.1s;

Animation(关键帧动画)

css

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }}.animate {
  animation: fadeIn 0.5s ease-in-out forwards;}


7. 其他视觉效果

属性说明常用值
opacity不透明度0(透明)→ 1(不透明)
cursor鼠标样式pointerdefaultnot-allowedmove
pointer-events穿透点击none(让元素不响应鼠标事件)
filter滤镜效果blur(5px)brightness(0.8)grayscale(100%)
backdrop-filter背景滤镜(毛玻璃效果)blur(10px)
mix-blend-mode混合模式multiplyscreenoverlay

8. 表格与列表样式

表格

属性说明常用值
border-collapse边框合并collapseseparate
caption-side表格标题位置topbottom
table-layout布局算法fixed(固定布局,提升渲染速度)

列表

属性说明常用值
list-style-type列表标记nonediscdecimal
list-style-position标记位置insideoutside

9. 响应式与单位

常用相对单位

单位说明
rem相对于根元素 font-size
em相对于当前元素 font-size
vw / vh视口宽度的 1% / 视口高度的 1%
vmin / vmax视口较小/较大边长的 1%
%相对于父元素同属性值
calc()动态计算,例如 calc(100% - 20px)

媒体查询示例

css

/* 移动端优先 */.container { width: 100%; }@media (min-width: 768px) {
  .container { width: 750px; }}@media (min-width: 1200px) {
  .container { width: 1170px; }}/* 暗色模式 */@media (prefers-color-scheme: dark) {
  body { background: #222; color: #fff; }}


10. 实用技巧速查

需求实现方式
水平居中(块元素)margin: 0 auto; + 有宽度的块
水平居中(内联/行内块)父级 text-align: center;
垂直居中(单行文本)父级 line-height 等于 height
垂直居中(Flex)父级 display: flex; align-items: center;
垂直居中(Grid)父级 display: grid; align-content: center;
水平垂直居中(绝对定位)position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
隐藏元素(不占位)display: none;
隐藏元素(占位,不可见)visibility: hidden;
清除浮动(clearfix).clearfix::after { content: ""; display: table; clear: both; }


评论(0条)

请登录后评论
ziyuan

ziyuan Rank: 16

0

0

0

( 此人很懒并没有留下什么~~ )

首页

栏目

搜索

会员