如何用html5和css3设置文字样式
时间: 2024-02-05 15:12:27 浏览: 16
要设置文字样式,可以使用HTML5和CSS3中的许多属性和值。以下是一些常用的属性和值:
1. font-family:设置字体系列,例如“Arial”或“Times New Roman”。
2. font-size:设置字体大小,例如“12px”或“1.2em”。
3. font-weight:设置字体的粗细程度,例如“bold”或“normal”。
4. font-style:设置字体的样式,例如“italic”或“normal”。
5. color:设置字体颜色,例如“#000000”或“red”。
6. text-align:设置文本对齐方式,例如“left”、“right”、“center”或“justify”。
7. text-decoration:设置文本装饰效果,例如“underline”、“overline”、“line-through”或“none”。
以下是一个简单的例子:
```html
<!DOCTYPE html>
<html>
<head>
<title>文字样式</title>
<style>
body {
font-family: Arial, sans-serif;
font-size: 16px;
color: #333;
text-align: center;
}
h1 {
font-size: 32px;
font-weight: bold;
color: #ff6600;
text-decoration: underline;
}
p {
font-size: 18px;
font-style: italic;
color: #666;
text-align: justify;
}
</style>
</head>
<body>
<h1>标题</h1>
<p>这是一段文本。</p>
</body>
</html>
```
在上面的例子中,我们设置了整个页面的字体系列、字体大小、颜色和文本对齐方式。我们还设置了标题的字体大小、粗细程度、颜色和下划线效果,以及一段文本的字体大小、样式、颜色和对齐方式。