例如,这个JSFiddle:https://jsfiddle.net/qmn8q2ck/
<p>
<span> This is some multiline text. This is some multiline text. </span><span>This is some multiline text. This is some multiline text. This is some multiline text. This is some multiline text. This is some multiline text. This is some multiline text. This is some multiline text. </span>
</p>
span {
background-color: red;
display: inline;
}
但是,我注意到浏览器突出显示行之间没有空格,并且具有我想要的效果。
我如何获得此效果?
编辑以显示需要显示:内联和影响span元素而不是整个段落。
答案 0 :(得分:3)
您还可以添加到span css display:inline-block
span {
background: red;
display: inline-block;
}
DEMO :http://jsfiddle.net/qmn8q2ck/
或添加填充
DEMO :http://jsfiddle.net/ckhfa8hc/
span {
background-color: red;
display: inline;
padding-top: 1px;
}
答案 1 :(得分:1)
使用css line-height属性
p { /* or span as you like */
line-height: 90%; /* Try some values here */
}
答案 2 :(得分:1)
您应该将background-color属性应用于段落而不是span
p {
background-color: red;
}
试试这个