【发布时间】:2017-04-30 03:22:33
【问题描述】:
所以我一直在使用 Chris 的文章 https://css-tricks.com/multi-line-padded-text/ 来帮助我获得一些带有背景的居中文本。唯一的问题是我希望背景是半透明的,我想不出办法。我玩过线高和填充,但无法提出解决方案。
我想要做的是停止每行的背景重叠,但确保每行之间的空间相同。
<div class="ui-section__component">
<div class="comp--hero-text">
<h2>You're all clear, kid. Let's blow this thing and go home! You're all clear, kid. Let's blow this thing and go home!</h2>
</div>
</div>
$white: #fff;
$max-width: 1024px;
$small-spacing: 0.75em;
.ui-section__component{
background-color: green;
display: flex;
height: 500px;
width: 700px;
}
.comp--hero-text {
align-self: center;
margin: 0 auto;
max-width: $max-width - 200px;
text-align: center;
width: 80%;
h2 {
background-color: rgba($white, 0.85);
box-decoration-break: clone;
box-shadow: $small-spacing / 2 0 0 rgba($white, 0.85), -$small-spacing / 2 0 0 rgba($white, 0.85);
display: inline;
line-height: 1.5;
padding: 0.5em 0;
}
}
我的代码可以在 Code Pen 上找到:http://codepen.io/rmaspero/pen/VmVwNx
【问题讨论】: