CSS文本属性

CSS文本属性

在CSS中,可以使用以下属性来设置文本的样式和布局:

1.color : 设置文本颜色。可以使用颜色名称、十六进制值或RGB值来指定颜色:

css 复制代码
p{
	color:red;
}
  1. font-family : 设置文本的字体系列。可以指定一个或多个字体名称作为备选项
css 复制代码
p{
	font-family: Arial,sans-serif;
}

3.font-size : 设置文本字体大小。可以使用绝对单位或相对单位来指定大小

css 复制代码
p{
	font-size:16px;
}
  1. font-weight : 设置文本的粗细。常见取值有normal , bold(加粗) ,以及数值
css 复制代码
p{
	font-weight : bold;
}
  1. text-align : 设置文本对齐方式。常见的取值有 (左对齐)、 (右对齐)、 (居中对齐)、 (两端对齐)
css 复制代码
p {
  text-align: left;    /* 左对齐(默认) */
  text-align: center;  /* 居中 */
  text-align: right;   /* 右对齐 */
  text-align: justify; /* 两端对齐 */
}
  1. text-decoration : 用于设置文本修饰效果,如下划线和删除线。常见的取值有none (无修饰), underline(下划线),和line-through(删除线):
css 复制代码
.link {
  text-decoration: underline solid #f00 2px; /* 组合写法 */
  /* 等效于: */
  text-decoration-line: underline;
  text-decoration-style: solid;
  text-decoration-color: #f00;
  text-decoration-thickness: 2px;
}
  1. line-height : 设置文本行高,即行与行之间的垂直间距。可以使用无单位的数值或百分比来指定行高
css 复制代码
p {
  line-height: 1.6;     /* 无单位值:相对于字体大小 */
  line-height: 24px;    /* 固定值 */
}

以下是一个示例

html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>CSS文本属性示例</title> <!-- 修正标题拼写 -->
    <style>
        .custom-text {
            color: red;
            font-family: Arial, sans-serif;
            font-size: 18px;
            font-weight: bold;
            text-align: center;
            text-decoration: underline;
            line-height: 1.5;  /* 补充分号保持一致性 */
        }
    </style>
</head>
<body>
    <p class="custom-text">This is a custom text example.</p>
    <p>This is a regular paragraph.</p>
</body>
</html>
相关推荐
大橙子额4 分钟前
【解决报错】Cannot assign to read only property ‘exports‘ of object ‘#<Object>‘
前端·javascript·vue.js
RFCEO5 分钟前
前端编程 课程十六、:CSS 盒子模型
css·前端基础课程·css盒子模型·css盒子模型的组成·精准控制元素的大小和位置·css布局的基石·内边距(padding)
爱喝白开水a2 小时前
前端AI自动化测试:brower-use调研让大模型帮你做网页交互与测试
前端·人工智能·大模型·prompt·交互·agent·rag
董世昌412 小时前
深度解析ES6 Set与Map:相同点、核心差异及实战选型
前端·javascript·es6
吃杠碰小鸡3 小时前
高中数学-数列-导数证明
前端·数学·算法
kingwebo'sZone3 小时前
C#使用Aspose.Words把 word转成图片
前端·c#·word
xjt_09013 小时前
基于 Vue 3 构建企业级 Web Components 组件库
前端·javascript·vue.js
我是伪码农3 小时前
Vue 2.3
前端·javascript·vue.js
夜郎king4 小时前
HTML5 SVG 实现日出日落动画与实时天气可视化
前端·html5·svg 日出日落
夏幻灵5 小时前
HTML5里最常用的十大标签
前端·html·html5