简体   繁体   English

用填充和替代颜色添加上划线和下划线

[英]adding overline and underline with padding and alternate color

As the title says, I'm looking for help with adding lines on top of a header text with a different color than the text. 如标题所述,我正在寻找有关在标题文本顶部添加颜色与文本不同的行的帮助。 I tried adding padding, margin and color in the class with overline and underline to no effect. 我尝试在类中使用上划线和下划线添加填充,边距和颜色,但没有任何效果。 Here is my HTML and CSS: 这是我的HTML和CSS:

 .lines { text-decoration-line: overline underline; margin: 20px; } 
 <div class="row"> <div class="col-md-7 justify_text"> <h2 class="lines">WHO WE ARE</h2> <div class="col-md-5"> <img src="img/pic2.jpg" class="img-responsive"> </div> </div> </div> 

Here is the effect that I want to show: 这是我要显示的效果:

在此处输入图片说明

You can use the :after and :before pseudoelemnts to add the lines. 您可以使用:after:before伪元素添加行。 Here is an example: 这是一个例子:

 .lines { position: relative; padding: 10px 0; } .lines:before { content: ''; position: absolute; top: 0; left: 0; width: 30%; height: 2px; background: red; } .lines:after { content: ''; position: absolute; bottom: 0; left: 0; width: 30%; height: 2px; background: blue; } 
 <div class="row"> <div class="col-md-7 justify_text"> <h2 class="lines">WHO WE ARE</h2> <div class="col-md-5"> <img src="img/pic2.jpg" class="img-responsive"> </div> </div> </div> 

Hope it helps you. 希望对您有帮助。

Another way to do it is to use border properties : 另一种方法是使用border属性:

 h2 { display: inline-block; border-top: 2px solid green; border-bottom: 2px solid orange; padding-top: 10px; padding-bottom: 10px; } 
 <h2>WHO WE ARE</h2> 

Another idea with gradient and you will have more flexibility to control colors and sizes: 关于渐变的另一个想法,您将可以更加灵活地控制颜色和大小:

 .lines { position: relative; padding: 10px 0; display:inline-block; background: linear-gradient(red,red) top center/100% 2px, linear-gradient(blue,blue) bottom center/80% 2px; background-repeat:no-repeat; } 
 <h2 class="lines">WHO WE ARE</h2> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM