css属性使用手册

字体属性

属性 说明 示例 备注
font-family 设置字体类型 font-family: Arial, sans-serif; 建议提供备用字体
font-size 设置字体大小 font-size: 16px;最小12px 常用单位:px, em, rem, %
font-weight 设置字体粗细 font-weight: bold; 常用值:normal, bold, 400, 700
font-style 设置字体样式 font-style: italic; normal(正常)、italic(斜体)
font-variant 设置小型大写字母 font-variant: small-caps; 将小写字母显示为小型大写
line-height 设置行高(行间距) line-height: 1.5; 无单位数字或 px/em 等
font ​字体简写属性​​(复合属性) font: italic bold 16px Arial; 有顺序要求,见下方

font------ ​​字体简写属性(复合属性)​

可以将多个字体相关的属性合并为一个声明,​​但必须按照正确的顺序书写​​。

​语法顺序(重要!):​

font: font-style font-variant font-weight font-size/line-height font-family;

⚠️ font-sizefont-family是​​必填项​ ​,且 font-family必须放在最后!


背景属性

属性 说明 示例
background-color 设置元素的背景颜色 background-color: #fff;
background-image 设置背景图片 background-image: url("image.jpg");
background-repeat 设置背景图片是否及如何重复 repeat, no-repeat, repeat-x, repeat-y
background-position 设置背景图片的位置 center, top left, 50% 50%, x y
background-size 设置背景图片的尺寸 cover, contain, 100px 200px, 50%
background-attachment 设置背景图片是否固定(滚动时是否滚动) scroll(默认), fixed
background ​背景复合属性(简写)​ background: #fff url(img.png) no-repeat center center / cover;

✅ 推荐使用 ​background简写属性​​,可以一次性设置多个背景相关样式,代码更简洁。

文本属性

属性 说明 示例
color 设置文本颜色 color: #333;
text-align 设置文本的水平对齐方式 left, center, right, justify
text-decoration 设置文本的装饰线(如下划线) none, underline, line-through, overline
text-transform 控制文本的大小写 none, uppercase, lowercase, capitalize
text-indent 设置首行文本缩进 2em
letter-spacing 设置字符间距 1px, 0.5em
word-spacing 设置单词间距 2px
line-height 设置行高(行间距) 1.5, 24px
white-space 控制空白符与换行的处理方式 normal, nowrap, pre
text-shadow 设置文本阴影 2px 2px 4px gray
direction 设置文本方向 ltr(默认), rtl
text-overflow 设置文本溢出时的显示方式 ellipsis(配合 overflowwhite-space

表格属性:

html 复制代码
<table>
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>张三</td>
      <td>25</td>
    </tr>
    <tr>
      <td>李四</td>
      <td>30</td>
    </tr>
  </tbody>
</table>

对应的标签说明:

标签 说明
<table> 表格整体容器
<tr> 表格的一行(table row)
<td> 表格的一个单元格(table data / 普通单元格)
<th> 表头单元格(table header / 通常加粗居中)
<thead> 表格头部(语义化,可选)
<tbody> 表格主体(语义化,可选)
<tfoot> 表格底部(语义化,可选)

css常用表格属性:

属性 说明 示例/常用值
border 设置表格或单元格的边框 border: 1px solid #ccc;
border-collapse 设置边框是否合并(关键!) collapse(合并边框)、separate(分开)
border-spacing 单元格之间的间距(仅当 border-collapse: separate时生效) border-spacing: 10px;
width/ height 表格的宽度与高度 width: 100%;
text-align 单元格内容的水平对齐 left, center, right
vertical-align 单元格内容的垂直对齐 top, middle, bottom
caption-side 表格标题(<caption>)的位置 top(默认)、bottom
empty-cells 是否显示空单元格的边框和背景 show, hide
table-layout 表格布局算法 auto(默认,根据内容调整)、fixed(固定列宽,更快渲染)
相关推荐
用户3076752811272 分钟前
💡 从"傻等"到"流淌":我在AI项目中实现流式输出的血泪史(附真实代码+深度解析)
前端
bluceli3 分钟前
前端性能优化实战指南:让你的网页飞起来
前端·性能优化
SuperEugene5 分钟前
Vue状态管理扫盲篇:如何设计一个合理的全局状态树 | 用户、权限、字典、布局配置
前端·vue.js·面试
没想好d6 分钟前
通用管理后台组件库-9-高级表格组件
前端
阿虎儿9 分钟前
React Hook 入门指南
前端·react.js
核以解忧32 分钟前
借助VTable Skill实现10W+数据渲染
前端
WangHappy34 分钟前
不写 Canvas 也能搞定!小程序图片导出的 WebView 通信方案
前端·微信小程序
李剑一39 分钟前
要闹哪样?又出现了一款新的格式化插件,尤雨溪力荐,速度提升了惊人的45倍!
前端·vue.js
闲云一鹤1 小时前
Git LFS 扫盲教程 - 你不会还在用 Git 管理大文件吧?
前端·git·前端工程化
阿虎儿1 小时前
React Context 详解:从入门到性能优化
前端·vue.js·react.js