I have a background image on top of which there is some text. It is very hard to read the text because of the background. I would like to add a white background just around the text itself, such that the text could be easily read. How can I accomplish this using CSS/Javascript/jQuery ?
+7
A:
i have the text contained in a <span> </span>
with background-color:White; or whatever you want
ThanosPapathanasiou
2010-04-22 12:59:37
A:
well, "text" is a little bit imprecise. text can be in a paragraph, a div, a span etc.
if for instance, the 'text' you want to give a background is wrapped in spans, its just
$('span').css('background-color', 'white');
for instance. Another way, which doesn't have the best performance is to call
$('*').each(function(){
if(typeof $(this).text != "undefined")
$(this).css('background-color', 'white');
}
Kind Regards
--Andy
jAndy
2010-04-22 13:00:23
jQuery is overkill for this when a very simple css rule would do.
Nick Craver
2010-04-22 13:01:18
A:
I assume your background image is in a DIV or something... so you can nest the text inside.
For example... if you curently have:
<div>Some Text</div>
div{background:url(/path/to/image.png);}
You could change it to this:
<div><p>Some Text</p></div>
div{background:url(/path/to/image.png);}
div p{background:#fff;}
Good luck!
Brant
2010-04-22 13:00:26
+3
A:
Wrap your text with a span:
<span class="white_bg">Your text here</span>
And put this in your CSS file:
.white_bg
{
background-color: #ffffff;
padding: 3px; /*add this if you want a bit of space around the text*/
}
That should do it.
Kyle Sevenoaks
2010-04-22 13:01:26
+1
A:
You could also use text-shadow that is implemented by the newest web browsers:
<div style="background: url(some_image.jpg); text-shadow: 1px 1px 1px #000; color: #fff">Readable</div>
or just do something like
<div style="background: url(some_image.jpg);"><p style="background: #fff">Readable</p></div>
Kai Sellgren
2010-04-22 13:02:13