我想在文字"关于我"下添加三种颜色的线性渐变边框底部。喜欢下划线。我已尝试在.section-divider中设置背景:在线性渐变和填充之后,所有这些但最终将整个背景设置为线性渐变。
HTML:
<hr class="section-divider" data-content="ABOUT ME"></hr>
CSS:
.section-divider {
font-family: Lato-Regular;
line-height: 1em;
position: relative;
outline: 0;
border: 0;
color: black;
text-align: left;
height: 1.5em;
font-size: 20px;
}
.section-divider:before {
content: '';
background: black;
position: absolute;
left: 0;
top: 50%;
width: 100%;
height: 1px;
}
.section-divider:after {
content: attr(data-content);
position: relative;
display: inline-block;
color: black;
padding: 0 .5em;
line-height: 1.5em;
color: black;
background-color: white;
}
如果有人知道如何做到这一点或更好的方法来做到这一点,文字对齐左边更好一般让我知道,谢谢!
.section-divider {
font-family: Lato-Regular;
line-height: 1em;
position: relative;
outline: 0;
border: 0;
color: black;
text-align: left;
height: 1.5em;
font-size: 20px;
}
.section-divider:before {
content: '';
background: black;
position: absolute;
left: 0;
top: 50%;
width: 100%;
height: 1px;
}
.section-divider:after {
content: attr(data-content);
position: relative;
display: inline-block;
color: black;
padding: 0 .5em;
line-height: 1.5em;
color: black;
background-color: white;
}
&#13;
<hr class="section-divider" data-content="ABOUT ME"></hr>
&#13;
答案 0 :(得分:1)
您可以使用此代码。
.section-divider {
font-family: Lato-Regular;
line-height: 1em;
position: relative;
outline: 0;
border: 0;
color: black;
text-align: left;
height: 1.5em;
font-size: 20px;
}
.section-divider:before {
content: '';
position: absolute;
left: 0;
top: 50%;
width: 100%;
height: 1px;
margin: 0;
border: 0;
background: #333; /* Chrome,Safari4+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#34495e), color-stop(10%,#34495e), color-stop(10%,#207cca), color-stop(24%,#2989d8), color-stop(24%,#34495e), color-stop(42%,#34495e), color-stop(42%,#207cca), color-stop(70%,#207cca), color-stop(70%,#207cca), color-stop(70%,#34495e), color-stop(100%,#34495e)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #34495e 0%,#34495e 10%,#207cca 10%,#2989d8 24%,#34495e 24%,#34495e 42%,#207cca 42%,#207cca 70%,#207cca 70%,#34495e 70%,#34495e 100%); /* Chrome10+,Safari5.1+ */
background-image: -moz-linear-gradient(left, #34495e 0%, #34495e 9%, #207cca 10%, #2989d8 24%, #34495e 24%, #34495e 42%, #207cca 42%, #207cca 70%, #207cca 70%, #34495e 71%, #34495e 100%);
background-image: -o-linear-gradient(left, #34495e 0%, #34495e 9%, #207cca 10%, #2989d8 24%, #34495e 24%, #34495e 42%, #207cca 42%, #207cca 70%, #207cca 70%, #34495e 71%, #34495e 100%);
background-image: linear-gradient(left, #34495e 0%, #34495e 9%, #207cca 10%, #2989d8 24%, #34495e 24%, #34495e 42%, #207cca 42%, #207cca 70%, #207cca 70%, #34495e 71%, #34495e 100%); /* Chrome10+,Safari5.1+ */
}
.section-divider:after {
content: attr(data-content);
position: relative;
display: inline-block;
color: black;
padding: 0 .5em;
line-height: 1.5em;
color: black;
background-color: white;
}
<hr class="section-divider" data-content="ABOUT ME" />