i

Learn HTML and CSS in 10 Days

Selectors

The styling of elements in a web page is done using CSS. A selector assigns precisely which element or elements inside our HTML to target and apply styles like position, colour and size. Selectors may incorporate a mix of various qualifiers to choose remarkable components, all relying upon how explicit we wish to be. Like, think it as we may sometime want to choose either all the paragraph present on the web page or only some specific paragraph on the page.

Selectors commonly target the element, like or an attribute value like class or id value. Inside CSS, selectors are pursued with wavy sections (curly braces), {}, which include the styles to be applied to the chosenelement.Example – h1 {………….} - > Here the selector is focusing on all  element

Properties

As soon as the element gets selected, a property helps in specifying the styles needed for that element. Property names are written in the CSS code just after the selectors and enclosed within the curly braces. A colon precedes them. There are several properties linked with the elements, like colour, background, height, width, font-size etc.

Example – p {

background: ………;

font-size: ……..;

                       }

In the above code, two properties i.e. background and font size is applied to all the element.

Values

Till now, we have known the method to select an element and then determine the style for it using a property. A property without its behaviour is incomplete in CSS. Thus, to specify a behaviour, a value must be added to the property. Values are text that are present between the semicolon and the colon after the property name. 

Example – p {

background: Blue;

font-size: 10px;

                       }

Here all

elements are selected and the value of background property is set to blue and that of the font-size is set to 10px.

Thus, the CSS Syntax is:

p {

background: Blue;

font-size: 10px;

}

p – Selector

Blue – Value

background – Property

Realizing a couple of standard terms and the general sentence structure of CSS is an extraordinary beginning, yet we have a couple of more things to learn before bouncing in too far. We must take a much more in-depth look at the working process of selectors in CSS.

Working with Selectors

As said earlier, Selectors in CSS helps in identifying which HTML elements needs styling. It is essential to get into the ways to use selectors as well as how to leverage them. The 1st thing that we should start with is by familiarizing with different kinds of selectors.

Let's start with some of the most common types: type, class and ID selectors.

Type Selectors

Type selectors in CSS help in targeting elements with their element type. For example, if we want to target all paragraph element,.

Class Selectors

Class Selectors helps us in choosing the element based on the value of the class attribute it contains. Class selectors are much more precise and specific in selecting the elements. It does not select all identical elements but chooses only a particular group of the element having the same class attribute value.

Inside CSS, the class attribute value is preceded by a period (.).

then we will use p type selector

Example – p { ………….. }

In the above code, the class selector will select all the element having the class attribute value as firstclass, including paragraph and division elements.

ID Selectors

ID Selectors are much more specific and precise than class selectors. They focus mainly on a unique element at a time. As the class selectors take the help of class attribute value of an element, the ID selectors use the id attribute value of the element as a selector.

Note that id attribute values can only be used one time on a page. In CSS, a hash sign (#) precedes the id attribute value.

In the above code, the ID selector will provide CSS styling only to that element whose id attribute value is firstid.

Now we guess that everything is coming together. We have leant the steps to add elements to the HTML page. We are also well accustomed with the technique of providing style to it using CSS. Now it’s time to connect both these languages such that they work together hand in hand.