如何使用 CSS 样式化 hr 元素?
为了在 HTML 网页上分割内容,可以使用 <hr> 元素。<hr> 标签只包含开始标签,不需要结束标签。使用 <hr> 元素插入水平线。要样式化 <hr> 元素,边框属性起着重要作用。可以使用边框速记属性,或者如果要样式化水平线的特定区域,则可以使用 border-top、border-bottom、border-left 等属性。让我们看看如何使用 HTML 和 CSS 样式化 <hr> 元素。
设置 hr 元素
在我们的示例中,我们在这里设置了 <hr> 元素。设置了五个 <hr> 元素,以便使用类分别对其进行样式设置。
<hr class="solid"> <hr class="dashed"> <hr class="double"> <hr class="dotted"> <hr class="round">
实线
在这里,我们将创建一个实线,并使用 border-top 属性对其进行样式设置。
.solid {
border-top: 5px solid rgb(16, 2, 141);
}
虚线
在这里,我们将创建一个虚线,并使用 border-top 属性对其进行样式设置。
.dashed {
border-top: 5px dashed rgb(190, 13, 146);
}
双线
在这里,我们将创建一个双线,并使用 border-top 属性对其进行样式设置。
.double {
border-top: 5px double rgb(22, 145, 11);
}
点线
在这里,我们将创建一个点线,并使用 border 属性对其进行样式设置。
.dotted {
border: 5px dotted rgb(200, 255, 0);
}
圆角线
在这里,我们将创建一个点线,并使用 border-radius 属性对其进行样式设置。
.round {
border: 5px solid rgb(35, 196, 142);
border-radius: 5px;
}
示例
要使用 CSS 样式化 hr 元素,代码如下所示:
<!DOCTYPE html>
<html>
<head>
<style>
body{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 20px;
}
hr{
margin-bottom: 20px;
}
.solid {
border-top: 5px solid rgb(16, 2, 141);
}
.dashed {
border-top: 5px dashed rgb(190, 13, 146);
}
.double {
border-top: 5px double rgb(22, 145, 11);
}
.dotted {
border: 5px dotted rgb(200, 255, 0);
}
.round {
border: 5px solid rgb(35, 196, 142);
border-radius: 5px;
}
</style>
</head>
<body>
<h1 style="text-align: center;">HR styling example</h1>
<hr class="solid">
<hr class="dashed">
<hr class="double">
<hr class="dotted">
<hr class="round">
</body>
</html>
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP