PDA

View Full Version : Div - Background Color


Kay
02-21-2003, 01:08 PM
I'm using a global style sheet for all our web pages.
However, I sometimes need an occasional highligt, and I don't like to use colored lettering.
I sometimes us "<div>" inside a table cell, but I only want to highlight that particular division, not the whole cell.
What is the inline syntax to color the div only?
TIA for any help!

meow
02-21-2003, 01:13 PM
The style attribute.

<div style="color: blue">...</div>

But it's (almost always) better to give the DIV a class (or an ID if there's only one in the page).

<div class="special">

and in your CSS:

.special { color: blue }

thox
02-21-2003, 01:29 PM
As the thread question is about background color, the inline css would in fact be: <div style="background-color: yellow; display: inline;">text</div>.

The display: inline; part should solve your issue with highlighting part of the text in a table cell.

---------------------------------

I agree that it would be beneficial to move the style into your globally used stylesheet.

HTML for highlighting: <div class="highlight">Highlighted text</div>

Addition to CSS: .highlight { background-color: yellow; display: inline; }

If you are still having a problem with the color affecting the whole cell rather than just the div, i suggest you check the position of your DIV open and closing tags.

e.g. <td><div class="highlight">Highlighted text</div> and normal text</td>

---------------------------------

Note: sorry if I didn't understand what you meant by inline, I answered in both ways that I could understand you :D

Bosko
02-21-2003, 01:33 PM
better use:
tr div {background-color: HighLight}

Kay
02-21-2003, 02:07 PM
better use:
tr div {background-color: HighLight}
Not in this case - this would higlight the whole row, and the 'div' in question is usually inside a table cell.

What I need is a temporary bypassing of the existing style sheet for one particular division, inside a table cell.

Assigning a class to it and adding that to the existing style sheet looks like the best solution, since it won't affect any other pages at all.
Duh! And why didn't I think of that?
Answer - Didn't have my morning coffee yet!

Thank all - You Rock.

cg9com
02-21-2003, 02:41 PM
division with an inline display?
why not use span then?
thats what its for