Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent text-shadow from overlapping text on previous line

Is it possible to prevent text-shadow from overlapping text within the same element (e.g. a h1)? Please see an exaggerated example image below – in my use case I would like the text to be very bright white, but instead the shadow is overlapping it and causing murky grey areas.

Example of nasty text-shadow overlap

I made a reduced test case here to demonstrate: http://codepen.io/approach/pen/LgaIe

Note : I deliberately used a small line-height to highlight this issue

like image 765
Sam Baldwin Avatar asked Dec 16 '13 17:12

Sam Baldwin


People also ask

Can you have multiple text shadows?

By using a comma, we can specify multiple text shadows. Here we have created the first text shadow with the same color as th background to give a semi-3D effect.

How do I fix overlapping text on my website?

Simply reloading the page solves it. Screen resolution and text size affect this. Try sizing up or down with CTRL + or -. This resets the page zoom.

Which property is used to set shadow over the text?

The text-shadow CSS property adds shadows to text. It accepts a comma-separated list of shadows to be applied to the text and any of its decorations . Each shadow is described by some combination of X and Y offsets from the element, blur radius, and color.


1 Answers

You could consider putting another layer of text above the shadowed text:

Basic Working Example

<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;
}

Or to save a little time and typing:

jQuery Working Example

$(function () {
    $('.wrapper').children().clone().css({
        position: 'absolute'
    }).prependTo('body');
});
like image 118
apaul Avatar answered Sep 17 '22 18:09

apaul