简体   繁体   中英

How can I give background color to the text content inside a div in my html page.

I do not need to give background color to the entire div. I only need the background color where there is any text content.Please help me.

Hope this helps or for more better solution you can provide your fiddle

div {
height:2em; 
width:20em;
background-color:#333;
text-align:center;}

div span.textContent {
background-color:#000;
color:#FFF; }

I helped you Googled "CSS Text Highlight".

<p class="intro">
    Highlighting text on a web page can help bring important information immediately to
    the readers attention e.g., "<span style="background-color: #FFFF00">This text
    should is highlighted in yellow and probably caught your eye first.</span>"
</p>

Please see: http://www.computerhope.com/issues/ch001391.htm

Use span tag and apply background-color:#FFFF00;

<span style="background-color: #FFFF00;">In publishing and graphic design, lorem ipsum is a placeholder text commonly used to demonstrate the graphic elements of a document or visual presentation.</span>

This will look like,

在此处输入图片说明

You need specify the backgroun-color property

#box{
    background-color : red;
}

http://jsfiddle.net/lisssb/EFzNq/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM