如何使用 CSS 样式化标题?
要使用 CSS 样式化标题,我们可以使用各种CSS属性使其看起来更具吸引力。在本文中,我们将学习和理解如何使用不同的 CSS 属性来样式化标题。
使用 CSS 样式化标题
- 我们在div元素内使用了两个h1标题,以向标题添加内边距和背景颜色,div 的类名为 header 和 test。
- 在第一个标题(id 为 head1)中,我们使用了 "font-style: oblique;" 和 "text-align: center;" 属性来添加样式并将其居中对齐。
- 在第二个标题(类名为 head)中,我们使用了 "font-family" 和 "color: white;" 属性来添加字体系列并将文本颜色更改为白色。
示例
以下是实现上述步骤的完整示例代码。
<!DOCTYPE html>
<html>
<head>
<title>
To style a header with CSS
</title>
<style>
body {
margin: 10px;
}
.header {
padding: 30px;
background-color: bisque;
}
.test {
padding: 30px;
background-color: #04af2f;
}
#head1 {
font-style: oblique;
text-align: center;
}
.head {
font-family: "Segoe UI", Tahoma,
Geneva, Verdana,
sans-serif;
text-align: center;
color: white;
}
</style>
</head>
<body>
<div class="header">
<h1 id="head1">
Styling header with CSS
</h1>
<p>
For this header, we have used
CSS font-style and text-align
property to style the header.
</p>
</div>
<div class="test">
<h1 class="head">
Welcome to Tutorials Point.
</h1>
<p>
For this header, we have used
CSS font-family and color
property to style the header.
</p>
</div>
</body>
</html>
结论
在本文中,我们了解了如何使用 CSS 样式化标题。我们使用了 font-style、font-family、color、text-align 和 background-color 来样式化标题。
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP