5/7/21

CSS tutorials : CSS Selector & Different type of CSS Selectors Part 1

Hey Friends, in our last tutorials we have seen about CSS syntax. Now, in this tutorial, we are going to learn about CSS selectors. So let’s begin…

CSS Selectors

CSS Selectors are used to selecting the Html elements which you want to style. Selectors are select Html elements by their id, class, attributes, type, etc. 

There are several different types of CSS selectors are:- 

  • CSS Element Selector
  • CSS Id Selector
  • CSS Class Selector
  • CSS Universal Selector
  • CSS Group Selector

CSS Element Selector

In this type of CSS Selector the selector select by the name of html element. Let’s See the Example below.

Example :- 

<html>

<head>

<title> CSS Elements Selector </title>

</head>

<style>

h1 { 

background-color: red;

color: Yellow; }

p { 

background-color: Yellow;

color : Green; }

</style>

<body>

<h1> This is a Heading. </h1>

<p> This is a Paragraph Tag. </p>

</body>

</html>

Output: - 

CSS ID Selector

This type of CSS Selector selects the element by its id.  It is good practice to give id or class name to each and every Html element. The main reason behind giving id and class name was you can select a particular element by its id or class name. 

Example: -

 <html>

<head>

    <title> CSS ID Selector </title>

</head>

<style>

    #heading {

        background-color: red;

        color: Yellow;

    }

    #heading2{

        background-color: black;

        color: white;

    }


    #para {

        background-color: Yellow;

        color: Green;

    }

</style>

<body>

    <h1 id="heading"> This is a Heading. </h1>

    <h2 id = "heading2"> This is another heading</h2>

    <p id="para"> This is a Paragraph Tag. </p>

</body>

</html>

Note:- For Selecting the Html Element by its id. Always use "#" first, then the id name. 

Output: -


"+y+""}else{if(A==5){c+='
  • '+w+""+y+"
  • "}else{if(A==6){c+='
  • "+w+'
    '+u+""+y+"
  • "}else{c+='
  • "+w+"
  • "}}}}}s.innerHTML=c+=""+y;d.callBack()};randomRelatedIndex=h;showRelatedPost=g;j(d.homePage.replace(/\/$/,"")+"/feeds/posts/summary"+e+"?alt=json-in-script&orderby=updated&max-results=0&callback=randomRelatedIndex")})(window,document,document.getElementsByTagName("head")[0]); //]]>

    0 comments:

    Post a Comment

    Follow on Twitter

    Linkedin

    Categories

    Contact Form

    Name

    Email *

    Message *

    Mad About Computer. Powered by Blogger.
    This site is in no way affiliated with or endorsed by specified business. It exists as a compendium of supporting information intended for informational purposes only. If you want to buy this website, please don't hesitate to contact us via e-mail: "d e n a c c 9 7 7 (at) g m a i l (dot) c o m" (delete spaces) or you can find and buy it on Afternic domain auctions.