简体   繁体   English

两个词之间的水平线

[英]Horizontal line between two words

How can I add a line between this two words with css: 如何使用CSS在这两个单词之间添加一条线:

Last Action Items------------------------------View more---- 最后行动项目------------------------------查看更多----

Without the "-" 不带“-”

I did this: https://jsfiddle.net/3L766kdo/1/ but I think there is a better way to do it (with the line surrounding View More) 我这样做了: https : //jsfiddle.net/3L766kdo/1/但我认为有更好的方法可以做到(查看更多内容)

HTML HTML

<div class='container c-decorated-header'>
  <h3><span>Last Action items</span></h3>
  <div class='c-decorated-header_link-view-more'>
    <a href="www.something.com">View More</a>
  </div>
<div>

SCSS SCSS

.c-decorated-header {
  position: relative;
  h3 {
    position: relative;
    color: #7B8291;
    width: 79%;
    text-align: left;
    border-bottom: 1px solid #e2e2e6;
    line-height: 0.1em;
    margin: 35px 0 0px;
  }
  h3 span {
    position: relative;
    font-size: .6em;
    font-weight: 600;
    font-stretch: condensed;
    background: #f5f4f4;
  }
  &_link-view-more {
    position: absolute;
    width: 96%;
    text-align: right;
    top: -5px;
    padding-right: 40px;
    font-size: 14px;
    font-weight: 400;
    font-family: 'Open Sans', sans-serif;
    color: rgb(87, 135, 253);
    text-decoration: none;
    text-align: right;
  }
}

Maybe using text-decoration: 也许使用文本装饰:

 Last Action Items<span style="text-decoration: line-through">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>View more<span style="text-decoration: line-through">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> 

Or use an inline-block 或使用inline-block

 Last Action Items<span style="display:inline-block; width:100px; border-bottom: 1px solid black; line-height:0">&nbsp;</span>View more 

This is a somewhat cleaner version of @RobAu his second solution. 这是@RobAu的第二种解决方案,它的版本稍微干净一些。 It should work. 它应该工作。

 span { display:inline-block; border-bottom: 1px solid black; line-height:0 } 
 Last Action Items<span style="width: 100px">&nbsp;</span>View more<span style="width: 50px">&nbsp;</span> 

The solution demonstrated in the Code Snippet embedded below utilizes existing elements with no further additions or adjustments to the DOM, or html structure. 下面嵌入的代码段中演示的解决方案利用现有元素,而无需对DOM或html结构进行进一步添加或调整。

An absolutely positioned pseudo-element is used to function as the required horizontal line resulting in the intended behaviour. 绝对定位的伪元素用于充当所需的水平线,从而导致预期的行为。

Code Snippet Demonstration: 代码段演示:

 .c-decorated-header { position: relative; } .c-decorated-header h3 { position: relative; color: #7B8291; text-align: left; } .c-decorated-header h3:after { content: ""; height: 1px; position: absolute; right: 0; left: 100px; top: 0; bottom: 0; margin: auto; background: #e2e2e6; } .c-decorated-header h3 span { position: relative; font-size: .6em; font-weight: 600; font-stretch: condensed; background: #f5f4f4; } .c-decorated-header_link-view-more { position: absolute; top: -5px; right: 40px; font-size: 14px; font-weight: 400; font-family: 'Open Sans', sans-serif; color: #5787fd; text-decoration: none; background: white; padding: 5px; } 
 <div class='container c-decorated-header'> <h3><span>Last Action items</span></h3> <div class='c-decorated-header_link-view-more'> <a href="www.something.com">View More</a> </div> <div> 

JSFiddle Demonstration JSFiddle演示

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

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