Ways to target elements in CSS
CSS plays a vital role in creating a design of the webpage. If you add a style in a certain element or tag on the webpage, for that you need to understand how to particularize those elements. There are three main approaches to achieve:
- With the help of tag, e.g. target the
body
orp
ordiv
- With the help of the class, you have specified in your HTML. Let suppose, if we have div with class .container, so you can target it with
container class.
- With the help of ID, you have specified in your HTML. Let suppose, if we have a link with the ID
form-button
you can target it with#form-button
/* tag */
body { ... }
/* class */
.
container{ ... }
/* id */
#form-button { ... }