Let's say I have the following:
<DIV class="msg-warn">
<SPAN>some message</SPAN>
</DIV>
I would like to add a background-color
to the msg-warn
class on the DIV
as to have the SPAN
inherit the said background-color. I can't apply a class to the SPAN
.
How can I achieve this? (no javascript please, just CSS)
EDIT: I found that the DIV
inherits something that makes it 1px in height...
It should be used only when no other semantic element is appropriate. <span> is very much like a <div> element, but <div> is a block-level element whereas a <span> is an inline element.
The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute. The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline element.
The span tag is just like a div, which is used to group similar content so it can all be styled together. But span is different in that it is an inline element, as opposed to div , which is a block element. Also, keep in mind that span itself does not have any effect on its content unless you style it.
Span and div are both generic HTML elements that group together related parts of a web page. However, they serve different functions. A div element is used for block-level organization and styling of page elements, whereas a span element is used for inline organization and styling.
Just add it to .msg-warn
if you want to style the whole class and have it inherit.
.msg-warn {
background-color:#F00;
}
If you want to style all <span>
s within .msg-warn target like this:
.msg-warn span {
background-color:#F00;
}
If you want to style all direct descendant <span>
s (immediate children, not children of children) use >
.msg-warn > span {
background-color:#F00;
}
Have you tried something like the following?
div.msg-warn > span {
background-color: #f00;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With