HTML 中的 hr 水平線預設帶有一種立體的陰影觀感,這是由於它的上下邊框顏色不同造成的。想去掉這層陰影其實很簡單。
hr 預設高度約為 2px,其中 border-top 為 1px、顏色偏黑,border-bottom 為 1px、顏色偏灰。兩種深淺不同的線條疊在一起,看起來就像有陰影。
只要在 CSS 裡把 border-bottom 或 border-top 其中一個設為 none,陰影感就消失了。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Demo</title>
<style type="text/css">
.hrtest {
height: 20px;
width: 50px;
border-top: 1px solid red;
border-left: none;
border-right: none;
border-bottom: none;
}
</style>
</head>
<body>
<hr class="hrtest">
</body>
</html>
這樣一來,水平線就只剩下一條乾淨的實線,能更好地融入現代化的介面設計中。