What is selector and universal selector?

Posted by

Universal Selector

A universal selector is a selector that matches any element type’s name instead of selecting elements of a particular type. The universal selector becomes helpful when you wish to put a specific style in all the HTML elements within your web page

syntax

* {
     property : value;
  }

uses the asterisk (“*”) symbol used for denoting the selector as a universal selector. It is usually written as an asterisk followed by a selector. The * is used for selecting all elements. This asterisk also has the capability to select all elements that are inside another element.

example

* {
     margin : 0px;
     padding : 0px;
  }

There are some additional properties of Universal selector, where you can make use of a combination of asterisk with namespace:

  • ns|* – this will allow you to match all elements within the namespace ns.
  • *|* – this will allow you to match simply all elements.
  • |* – this will allow you to match all elements that are without any declared namespace.

Selectors

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.

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

example

<!DOCTYPE html>  
<html>  
<head>  
<style>  
p{  
    text-align: center;  
    color: blue;  
}   
</style>  
</head>  
<body>  
<p>This style will be applied on every paragraph.</p>  
<p id="para1">Me too!</p>  
<p>And me!</p>  
</body>  
</html>
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x