如何用HTML5和CSS3设置文字样式
时间: 2024-02-06 10:08:45 浏览: 71
要设置文字样式,可以使用CSS3中的font属性来控制字体、字号、颜色等,例如:
```html
<!DOCTYPE html>
<html>
<head>
<title>设置文字样式</title>
<style>
body {
font-family: Arial, sans-serif; /* 设置字体 */
font-size: 16px; /* 设置字号 */
color: #333; /* 设置字体颜色 */
line-height: 1.5; /* 设置行高 */
text-align: center; /* 设置文本居中 */
}
h1 {
font-size: 32px; /* 设置标题字号 */
font-weight: bold; /* 设置标题加粗 */
color: #f00; /* 设置标题颜色 */
}
p {
margin: 20px 0; /* 设置段落上下边距 */
}
</style>
</head>
<body>
<h1>欢迎来到我的网站</h1>
<p>这是一段普通文字,可以设置字体、字号、颜色等。</p>
<p>这是另一段文字,可以设置行高、上下边距等。</p>
</body>
</html>
```
以上是一个例子,其中`body`元素设置了字体、字号、颜色、行高和文本居中,`h1`元素设置了标题字号、加粗和颜色,`p`元素设置了段落上下边距。需要注意的是,CSS3中的font属性还可以设置其他属性,如字体样式、字体变形、字间距等,可以根据实际需要进行调整。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)