CSS 字体与文本样式笔记

一、字体族设置(font-family)

语法:

font-family: 字体1, 字体2, ...;

示例:

p {

font-family: "Microsoft Yahei", Arial, sans-serif;

}


二、字体颜色(color)

语法:

color: 颜色值;

支持格式:

  • 英文名:red

  • 十六进制:#f00

  • RGB:rgb(255, 0, 0)

示例:

div { color: #f00; }

h1 { color: rgb(0, 0, 255); }


三、字体大小(font-size)

语法:

font-size: 数值+单位;

单位常用:px、em、rem

示例:

p { font-size: 16px; }


四、字体粗细(font-weight)

常用值:

  • normal(等于 400)

  • bold(等于 700)

  • 数字 100 ~ 900(越大越粗)

示例:

h1 { font-weight: bold; }

h2 { font-weight: 300; }


五、字体样式(font-style)

可选值:normal、italic、oblique

示例:

p { font-style: italic; }


六、文本对齐(text-align)

可选值:left、center、right、justify

示例:

h1 { text-align: center; }


七、首行缩进(text-indent)

示例:

p { text-indent: 2em; }


八、文本装饰线(text-decoration)

可选值:none、underline、overline、line-through

示例:

a { text-decoration: none; }

h4 { text-decoration: underline; }

div { text-decoration: overline; }

h5 { text-decoration: line-through; }


九、行高(line-height)

示例:

p { line-height: 1.5; }


十、字母间距(letter-spacing)

示例:

p { letter-spacing: 2px; }


十一、单词间距(word-spacing)

示例:

p { word-spacing: 5px; }


十二、文字大小写(text-transform)

可选值:none、uppercase、lowercase、capitalize

示例:

p { text-transform: uppercase; }


十三、字体综合简写(font)

语法顺序:

font-style font-weight font-size/line-height font-family

示例:

p {

font: italic bold 16px/1.5 Arial, sans-serif;

}

相关推荐
TeleostNaCl5 小时前
解决 Chrome 无法访问网页但无痕模式下可以访问该网页 的问题
前端·网络·chrome·windows·经验分享
charlie1145141915 小时前
CSS笔记4:CSS:列表、边框、表格、背景、鼠标与常用长度单位
css·笔记·学习·css3·教程
QX_hao6 小时前
【Go】--反射(reflect)的使用
开发语言·后端·golang
inferno6 小时前
Maven基础(二)
java·开发语言·maven
我是李武涯6 小时前
从`std::mutex`到`std::lock_guard`与`std::unique_lock`的演进之路
开发语言·c++
前端大卫7 小时前
为什么 React 中的 key 不能用索引?
前端
你的人类朋友7 小时前
【Node】手动归还主线程控制权:解决 Node.js 阻塞的一个思路
前端·后端·node.js
史不了7 小时前
静态交叉编译rust程序
开发语言·后端·rust
读研的武8 小时前
DashGo零基础入门 纯Python的管理系统搭建
开发语言·python