5/21/21

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

(4) CSS Group Selectors 

In CSS, you can also give the same style in any Html element just need to write the style at once. You just need to select the all the Html element at once and give them style which you want. This type of selection is done by Group Selectors. In simple words, you can style many Html elements just to select them at once. You don’t need to write style for all Html elements. 

Let Us See through an example:- 

In this example, we will show you that how one style sheet will style on all the Html elements with the help of group selectors. 

Example:- 

<html>
<head>
 <title> CSS Selectors </title>
</head>
<style>
    p, h1, h2, span {
        font: 120px;
        Color: red;
        Background-color: Yellow;
        border: 2px solid green;
    }
</style>
<body>
<h1> This is a 1st Heading. </h1>
<p>  Lorem, ipsum dololoam hic minus ducimus? Deserunt commodi eaque sit expedita. </p>
<span> This is a Span.</span>
<h2>This is 2nd heading. </h2>
<p>Lorem ipsum dolor oloremque consequatur repellendus magni? Reprehenderit aut asperiores id?</p>
</html> 

Output :- 

As you can see in the above example how all the Html elements group together and once CSS properties will apply to all of them. 

(5) CSS Universal Selectors 

CSS Universal Selectors is used when you want apply a particular CSS properties to all the html elements. 

Let’s see through an example :- 

<html>
<head>
 <title> CSS Selectors </title>
</head>
<style>
   * {
     background-color: rgb(207, 107, 107);
    }
</style>
<body>
<div> <p> This is a Paragraph inside Div Container.</p> </div>
<p> This is a Paragraph Outside the Div Container.</p>
<div> <span> This is a Span tag inside the Div Container. </span></div>
<div> <textarea> Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit, esse? 
</textarea></div>
<div> Lorem ipsum dolor sit amet consectetur adipisicing elit. Error, debitis? Lorem ipsum 
dolor sit amet consectetur, adipisicing elit. Error recusandae dolore eius eum asperiores?</div>
</html> 

Output :- 


In this example, we have applied the background-color CSS property to all the Html elements that why the background color of all the Html elements will change. But you can use a universal selector in many different ways. Let’s see through an amazing example. 

Example: -

<html>
<head>
 <title> CSS Selectors </title>
</head>
<style>
    div * {
        background-color: rgb(207, 107, 107);
  }
</style>
<body>
<div> <p> This is a Paragraph inside Div Container.</p> </div>
<p> This is a Paragraph Outside the Div Container.</p>
<div> <span> This is a Span tag inside the Div Container. </span></div>
<div> <textarea> Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit, esse?</textarea></div>
 <div> Lorem ipsum dolor sit amet consectetur adipisicing elit. Error, debitis? Lorem ipsum dolor sit amet consectetur, adipisicing elit. Error recusandae dolore eius eum asperiores?</div>
</html>

Output :- 

In the above example, we saw that how we used the universal selector for the elements which is inside the div containers. The CSS property only applies to the elements which are inside the div containers. It doesn’t affect the other elements which are outside the div container.

Hope you all understand. If you still have any problem regard this, then tell us by commenting below, we will definitely try to solve the problem.  


"+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.