{"id":7573,"date":"2013-01-28T11:54:37","date_gmt":"2013-01-28T11:54:37","guid":{"rendered":"http:\/\/vskills.in\/certification\/tutorial\/?p=7573"},"modified":"2024-04-12T14:17:05","modified_gmt":"2024-04-12T08:47:05","slug":"selectors-class-id-universal-etc","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/","title":{"rendered":"Selectors (class, ID, universal, etc.)"},"content":{"rendered":"<p><strong>Grouping<\/strong> &#8211; When several selectors have same rule to apply, they may be grouped into a comma-separated list. In this example, we condense three rules into one. Thus,<\/p>\n<p>h1 { font-family: sans-serif }<\/p>\n<p>h2 { font-family: sans-serif }<\/p>\n<p>h3 { font-family: sans-serif }<\/p>\n<p>is equivalent to: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h1, h2, h3 { font-family: sans-serif }<\/p>\n<p><strong>Universal selector<\/strong> &#8211; It is written as &#8220;*&#8221;, matches the name of any element type. It matches any single element in the document tree. For example: *[lang=fr] &nbsp;matches elements with attribute \u201clang=fr\u201d.<\/p>\n<p><strong>Type selectors<\/strong> &#8211; It matches every instance of the element type in the document tree. The following rule matches all H1 elements in the document tree:&nbsp; h1 { font-family: sans-serif }<\/p>\n<p><strong>Descendant selectors<\/strong> &#8211; It matches to the descendant of an element in the web page. It is of the form &#8220;A B&#8221; matches when an element B is an arbitrary descendant of some ancestor element A. As in example, consider the following rules:<\/p>\n<p>h1 { color: red }<\/p>\n<p>em { color: red }<\/p>\n<p>Although the intention of these rules is to add emphasis to text by changing its color, the effect will be lost in a case such as:<\/p>\n<p>&lt;H1&gt;This headline is &lt;EM&gt;very&lt;\/EM&gt; important&lt;\/H1&gt;<\/p>\n<p>We address this case by supplementing the previous rules with a rule that sets the text color to blue whenever an EM occurs anywhere within an H1:<\/p>\n<p>h1 { color: red }<\/p>\n<p>em { color: red }<\/p>\n<p>h1 em { color: blue }<\/p>\n<p>The third rule will match the EM in the following fragment:<\/p>\n<p>&lt;H1&gt;This &lt;SPAN class=&#8221;myclass&#8221;&gt;headline<\/p>\n<p>is &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;EM&gt;very&lt;\/EM&gt; important&lt;\/SPAN&gt;&lt;\/H1&gt;<\/p>\n<p><strong>Child selectors<\/strong> &#8211; It matches when an element is the child of some element. A child selector is made up of two or more selectors separated by &#8220;&gt;&#8221;. The following rule sets the style of all P elements that are children of BODY:<\/p>\n<p>body &gt; P { line-height: 1.3 }<\/p>\n<p>The following example combines descendant selectors and child selectors:<\/p>\n<p>div ol&gt;li p<\/p>\n<p>It matches a P element that is a descendant of an LI; the LI element must be the child of an OL element; the OL element must be a descendant of a DIV. Notice that the optional white space around the &#8220;&gt;&#8221; combinator has been left out. For information on selecting the first child of an element, please see the section on the :first-child pseudo-class below.<\/p>\n<p><strong>Adjacent sibling selectors<\/strong> &#8211; They have the following syntax: E1 + E2, where E2 is the subject of the selector. The selector matches if E1 and E2 share the same parent in the document tree and E1 immediately precedes E2, ignoring non-element nodes (such as text nodes and comments).<\/p>\n<p>Thus, the following rule states that when a P element immediately follows a MATH element, it should not be indented:<\/p>\n<p>math + p { text-indent: 0 }<\/p>\n<p>The next example reduces vertical space separating an H1 and an H2 that immediately follows it:<\/p>\n<p>h1 + h2 { margin-top: -5mm }<\/p>\n<p>The following rule is similar to the one in the previous example, except that it adds a class selector. Thus, special formatting only occurs when H1 has class=&#8221;opener&#8221;:<\/p>\n<p>h1.opener + h2 { margin-top: -5mm }<\/p>\n<p><strong>Class selectors<\/strong> &#8211; The period (.) notation is used for representing the class attribute for applying styles to all elements having the same class value. The attribute value must immediately follow the &#8220;period&#8221; (.). For example, we can assign style information to all elements with class~=&#8221;pastoral&#8221; as follows:<\/p>\n<p>.pastoral { color: green }<\/p>\n<p>Given these rules, the first H1 instance below would not have green text, while the second would:<\/p>\n<p>&lt;H1&gt;Not green&lt;\/H1&gt;<\/p>\n<p>&lt;H1 class=&#8221;pastoral&#8221;&gt;Very green&lt;\/H1&gt;<\/p>\n<p>To match a subset of &#8220;class&#8221; values, each value must be preceded by a &#8220;.&#8221;.<\/p>\n<p><strong>ID selectors<\/strong> &#8211; No two ID attributes can have the same value; and it uniquely identify an element. The ID attribute assigns an identifier to one element. A CSS ID selector contains a &#8220;#&#8221; immediately followed by the ID value, which must be an identifier. The following ID selector matches the H1 element whose ID attribute has the value &#8220;chapter1&#8221;:<\/p>\n<p>h1#chapter1 { text-align: center }<\/p>\n<p>ID selectors have a higher specificity than attribute selectors.<\/p>\n\n\n<p><a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/dhtml-and-javascript-developer\/\" target=\"_blank\" rel=\"noreferrer noopener\">Back to Tutorial<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Grouping &#8211; When several selectors have same rule to apply, they may be grouped into a comma-separated list. In this example, we condense three rules into one. Thus, h1 { font-family: sans-serif } h2 { font-family: sans-serif } h3 { font-family: sans-serif } is equivalent to: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h1, h2, h3 { font-family: sans-serif } Universal&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[3352],"tags":[1750],"class_list":["post-7573","page","type-page","status-publish","hentry","category-dhtml-and-javascript","tag-selectors"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Selectors (class, ID, universal, etc.) - Tutorial<\/title>\n<meta name=\"description\" content=\"Selectors (class, ID, universal, etc.). Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Selectors (class, ID, universal, etc.) - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Selectors (class, ID, universal, etc.). Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:47:05+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/\",\"name\":\"Selectors (class, ID, universal, etc.) - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2013-01-28T11:54:37+00:00\",\"dateModified\":\"2024-04-12T08:47:05+00:00\",\"description\":\"Selectors (class, ID, universal, etc.). Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Selectors (class, ID, universal, etc.)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Selectors (class, ID, universal, etc.) - Tutorial","description":"Selectors (class, ID, universal, etc.). Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/","og_locale":"en_US","og_type":"article","og_title":"Selectors (class, ID, universal, etc.) - Tutorial","og_description":"Selectors (class, ID, universal, etc.). Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:47:05+00:00","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/","name":"Selectors (class, ID, universal, etc.) - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2013-01-28T11:54:37+00:00","dateModified":"2024-04-12T08:47:05+00:00","description":"Selectors (class, ID, universal, etc.). Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/selectors-class-id-universal-etc\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Selectors (class, ID, universal, etc.)"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/7573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=7573"}],"version-history":[{"count":6,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/7573\/revisions"}],"predecessor-version":[{"id":82867,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/7573\/revisions\/82867"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=7573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=7573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=7573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}