is it possible to change font color across several divs and spans with css?
For example, I have HTML that goes like this:
some text ### some text
<div> some text in div</div>
some text
<div> some text
<span>some text</span>
</div>
some ### more text
Is there a way to change the color of the text 开发者_StackOverflow社区to, let's say, red between the ### marks?
PS. The question is not about scripting, the question about the resulting markup/css itself.
I'm not exactly sure what you're asking, so let's take the opportunity to go over some CSS basics:
This CSS will apply to all div
tags:
div
{
color: red;
}
This CSS will apply to all span
tags inside a div
:
div span
{
color: red;
}
This CSS will apply to all div
tags and all span
tags:
div, span
{
color: red;
}
If you want a CSS rule to apply to a certain section of code regardless of the elements in it, then you can put it in a wrapper, like so:
<div class="Wrapper">
<!-- Lots of different tags in here -->
</div>
Then, you can apply this CSS rule to match all tags of any type inside a div
with class Wrapper
:
div.Wrapper *
{
color: red;
}
Always wrap the text like in your example in span
tag. Don't throw the text like that. With that said, in general you can specify in .css file color
property for span
.
span{ color: Red }
But if you want specific span in a div to have a specific color then -
<div class="someClass">
<span>some text</span>
</div>
In .css,
.someClass { /* properties for the div */ }
.someClass span { color: Blue; /* other font properties */ }
精彩评论