Selectors in CSS3
Selectors are used to target specific elements in your HTML document so that you can apply styles to them. CSS3 introduces several new selectors that allow you to target elements more precisely.
html
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li class="selected">Item 3</li>
<li>Item 4</li>
</ul>
css
li:first-child {
color: red;
}
li.selected {
font-weight: bold;
}
In this example, we have used two selectors. The :first-child selector targets the first li element in the ul list and applies a red color to its text. The .selected selector targets the li element with the selected class and applies a bold font weight to its text.
No comments:
Post a Comment