我无法弄清楚如何使用CSS在元素上应用分割边框。
我试图实现的效果是:
红线和灰线占据元素宽度的百分比。我希望使用单个类将此效果应用于元素。
那些要求代码示例的人编辑:
<!-- spans width 100% -->
<div id="wrapper">
<h1 class="title">DDOS Protection </h1>
</div>
答案 0 :(得分:3)
红色文字和红色下划线?这有一些简单的CSS。
<span style='color:red; border-bottom: 1px solid red;'>DDOS</span>
<span style='color:#999; border-bottom: 1px solid #999;'>Protection</span>
答案 1 :(得分:0)
好吧,假设您想使用单个类,并且没有看到确切的标记,这将有效:
<div class="message">
<span>DDOS</span>
<span>Protection</span>
</div>
然后你的CSS看起来像这样:
.message span {
border-bottom: 1px solid #ccc;
padding-bottom: 5px;
color: #ccc;
}
.message span:first-child {
border-bottom-color: red;
color: red;
margin-right: 10px;
}
答案 2 :(得分:0)
您还可以尝试使用:before
和:after
:
.line {
background-color: #DDD;
padding: 5px 10px;
position: relative;
}
.line:before, .line:after {
content: '';
width: 10%;
height: 2px;
background-color: red;
position: absolute;
bottom: 0;
left: 0;
}
.line:after {
width: 90%;
background-color: green;
left: 10%;
}
答案 3 :(得分:0)
好的我已经制作了类似的但是要求垂直,但现在正在改变渐变方向以便它可以帮助你
Demo(适用于 Chrome ,如果有人知道跨浏览器,请随意编辑,因为我使用的旧浏览器无法测试)
CSS
div {
font: 40px Arial;
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#ff0505), color-stop(50%,#ff0000), color-stop(50%,#000000), color-stop(100%,#000000));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}