fbpx
Coding Basics WEB DEVELOPMENT

Learn Selectors, Id’s And Classes In CSS [TUTORIAL]

CSS 2

Hello friends today we learn about selectors. So, selectors are basically use to select the element we want to style.

Watch this tutorial on YouTube:

why we use selectors?

if we want to style a particular element in our HTML so the selectors are very helpful. There is a large variety of selectors but we learn about only tow selectors. Which is most commonly used by every web developer?

These selectors are class and Id.

The class and id selectors are very common to use in CSS. We can identify class and Id in our CSS document as a ( . ) sign and to the class using ( # ) sign.

In the class and ID’s the basic difference is that class can be used multiple times but Id’s are used only once at a time.

For the page, the id used only at once on the same page uses multiple classes to style our HTML documents. Let’s see some examples:

Code HTML:

<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8">
	<!---- The page title -->
	<title>Selectors in CSS</title>
	<!---- External css file main.css -->
	<link rel="stylesheet" type ="text/css" href ="main.css">
	
	</head>
	
	<body>
		
		<p class="r"> Ram, is very good man. </p>
		
		<p id="s"> Shyam, is very nice person. </p>
		
	</body>
		
</html>

The rel attribute is use for showing the relationship between the HTML and CSS document. Because we are using the href to link out CSS document to HTML document. So, the rel attribute is necessary to use whrn we use href.

Code CSS:

.r{
	color: red;
	}
#s{
	color: navy;
	}
      

Output:

CSS 2 output

you will find all example code in the following link

Git Hub Link

Tip: store the CSS and HTML file in the same folder.

Question:

[wp_quiz id=”2913″]

Also Read:

Share This Post To Your Friends

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *