我有一个跨越多行并具有背景颜色的跨度.我需要每条线在末尾都有10px的填充.文本将是动态的,所以我需要一个css或js解决方案,而不仅仅是使用nbsp标签进行黑客攻击(这就是我如何得到如下图所示的示例)
图片展示了我拥有的和我想要的东西之间的区别:

<h3><span class="heading">THE NEXT GENERATION OF CREATIVE TALENT</span><br/>
<span class="subhead">IT'S RIGHT HERE</span></h3>
h3 {
margin:0;
font-size: 42px;}
h3 .heading {
background-color: #000;
color: #00a3d0;}
h3 .subhead {
background-color: #00a3d0;
color: #000;}
Run Code Online (Sandbox Code Playgroud)
我想不出用css做任何方法,我正在考虑使用javascript来查找每一行的开头和结尾,并添加一个不间断的空格.
有没有人有任何想法如何实现这一目标?干杯
我已经在IE8中测试了这一点(在IE7中看起来不太糟糕)和最新版本的Chrome,Firefox,Opera,Safari.
Chrome的屏幕截图:

它有点愚蠢,说实话,可能比它的价值更复杂 - 基于JS的解决方案肯定会更容易理解.
这种技术有很多陷阱.
CSS:
#titleContainer {
width: 520px
}
h3 {
margin:0;
font-size: 42px;
font-weight: bold;
font-family: sans-serif
}
h3 .heading {
background-color: #000;
color: #00a3d0;
}
h3 .subhead {
background-color: #00a3d0;
color: #000;
}
div {
line-height: 1.1;
padding: 1px 0;
border-left: 30px solid #000;
display: inline-block;
}
h3 {
background-color: #000;
color: #fff;
display: inline;
margin: 0;
padding: 0
}
h3 .indent {
position: relative;
left: -15px;
}
h3 .subhead {
padding: 0 15px;
float: left;
margin: 3px 0 0 -29px;
outline: 1px solid #00a3d0;
line-height: 1.15
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div id="titleContainer">
<h3><span class="indent">
<span class="heading">THE NEXT GENERATION OF CREATIVE TALENT</span><br /><span class="subhead">IT'S RIGHT HERE</span>
</span></h3>
</div>
<!--[if IE]><style>
h3 .subhead {
margin-left: -14px
}
</style><![endif]-->
Run Code Online (Sandbox Code Playgroud)
box-shadow让它变得简单!
box-shadow:0.5em 0 0 #000,-0.5em 0 0 #000;
-moz-box-shadow:0.5em 0 0 #000,-0.5em 0 0 #000;
-webkit-box-shadow:0.5em 0 0 #000,-0.5em 0 0 #000;
Run Code Online (Sandbox Code Playgroud)