您可以在 伪元素上使用margin-right:-100%;和。(基于此答案:文本和透明背景下的行分隔符):vertical-align:middle;:after
h2 { font-size: 42px; line-height: 48px; width: 100%; overflow: hidden;}h2:before, h2:after { content: ''; display: inline-block; vertical-align:middle; width:50px; height:3px; border-top:1px solid #fff; border-bottom:1px solid #fff;}h2:after { width:100%; margin-right: -100%;}body{background-image: url('https://farm9.staticflickr.com/8760/17195790401_ceeeafcddb_o.jpg');background-repeat:no-repeat;background-size:cover;color:#fff;}<h2>HEALTH BENEFITS</h2><h2>HEALTH</h2>请注意,我还简化了CSS。



