如何避免text-shadow
重叠在同一元素内的文字上(例如 h1
)?请见下图,这是一个夸张的例子。在我的用例中,我希望文本非常明亮,但实际上阴影覆盖了它并导致混浊的灰色区域。
我在这里创建了一个简化的测试案例以进行演示:http://codepen.io/approach/pen/LgaIe
注意:我故意使用小的line-height
来凸显此问题。
如何避免text-shadow
重叠在同一元素内的文字上(例如 h1
)?请见下图,这是一个夸张的例子。在我的用例中,我希望文本非常明亮,但实际上阴影覆盖了它并导致混浊的灰色区域。
我在这里创建了一个简化的测试案例以进行演示:http://codepen.io/approach/pen/LgaIe
注意:我故意使用小的line-height
来凸显此问题。
<div class="cover">
<h1><a href="#">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit eveniet eos deleniti provident ab nam laborum at voluptatem est iste ratione quis error perspiciatis debitis.</a></h1>
</div>
.cover{
position:absolute;
top:0;
}
.cover h1 a{
color: white;
}
或者为了节省一点时间和打字:
$(function () {
$('.wrapper').children().clone().css({
position: 'absolute'
}).prependTo('body');
});
使用伪元素。
http://codepen.io/andrewtibbetts/pen/OXzvOd
首先,将内容重复到元素的一个属性中:
<div class="text-shadow" data-content="This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow.">This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow. This text has a shadow.</div>
.text-shadow {
position: relative;
text-shadow: 0 -.5em 1em black;
color: transparent;
&:after {
content: attr(data-content);
position: absolute;
top: 0;
left: 0;
color: #fff;
text-shadow: none;
}
}
line-height
。line-height
。 - Sam Baldwinh1 {
text-shadow: 0 0 2px white, 0 0 10px grey, 0 0 4px black;
}
你可以拥有无限数量的文本阴影。因此,首先放置一个白色阴影可能有助于清除灰色/黑色。调整像素等参数,使其按照你想要的方式工作。
line-height
增大,比如说line-height: 1.3em;
。