Want to know more about us and our multimedia, animation & web design courses, feel free to Contact Us. We would love to hear from you.
CSS selectors are used to select the content you want to style. Selectors are the part of CSS rule set. CSS selectors select HTML elements according to its id, class, type, attribute etc.
There are several different types of selectors in CSS.
The element selector selects elements based on the element name.
You can select all
elements on a page like this (in this case, all
elements will be center-aligned, with a red text color):
The class selector selects elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the name of the class.
In the example below, all HTML elements with class="center" will be red and center-aligned:
The id selector uses the id attribute of an HTML element to select a specific element. The id of an element should be 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.
The style rule below will be applied to the HTML element with id="para1":
If you want have same styles on different you can use selectors like this
Comments are used to explain the code, and may help when you edit the source code at a later date. Comments are ignored by browsers.
A CSS comment starts with
/* and ends with */. Comments can also span multiple lines:
The universal selector works like a wild card character, selecting all elements on a page. Every HTML page is built on content placed within HTML tags. Each set of tags represents an element on the page. Look at the following CSS example, which uses the universal selector:
The descendant selector or compound selector lets you combine two or more selectors so you can be more specific in your selection method. This type of selector has a higher priority than the other methods.
The attribute selector targets elements based on the presence and/or value of HTML attributes, and is declared using square brackets:
A pseudo-class uses a colon character to identify a pseudo-state that an element might be in—for example, the state of being hovered, or the state of being activated.
a:hover - a link when the user mouses over it
Let’s look at a common example:
|Monday To Friday||8:00 Am To 8:00Pm|
|Saturday & Sunday||8:00 Am To 5:00Pm|