I am trying to find the CSS syntax for a specific problem. I really searched but couldn't find answer. Here is the problem. My HTML markup is as follow:
<div>
<header>
<div class="container">
<div class="row">
my content that I want red
</div>
</div>
</header>
<div class="container">
<div class="row">
my content that I want blue
</div>
</div>
</header>
I would like to display "my content that I want red" in red, and "my content that I want blue" in blue, and I only can use CSS for that.
Does anyone knows the trick that will make it? sub classes cant work here unfortunately.
Thanks in advance,
The CSS id Selector The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.
When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your stylesheet. Instead of having two, three, or more CSS rules that do the same thing (set the color of something to red, for example), you use a single CSS rule that accomplishes the same thing.
You can create a selector that will target specific elements with the class applied.
If you want to use a class, use a full stop (.) followed by the class name in a style block. Next, use a bracket called a declaration block that contains the property to stylize the element, such as text color or text size. CSS Classes will help you stylize HTML elements quickly.
There's lots of options. It all really depends on your circumstances. Here's a couple without modifying the HTML:
Using parent element
.row { color: blue }
header .row { color: red }
Using :nth-of-type
.column:nth-of-type(1) .row { color: red }
.column:nth-of-type(2) .row { color: blue }
If you're willing to add additional markup, you could always add additional classes.
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