smus Posted October 16, 2018 Share Posted October 16, 2018 Is it possible to apply to several tags with one selector, not creating class for it? For example, I want a common property for all headings in the document: h1, h2, h3{color: orange;} <h1>h1</h1> <h2>h2</h2> <h3>h3</h3> Something like h^{color: orange;} for tag selectors? Link to comment Share on other sites More sharing options...
dsonesuk Posted October 16, 2018 Share Posted October 16, 2018 There is only 6?, you don't have apply a class to all, just the parent <div class="myheadercolor"> <h1>h1</h1> <h2>h2</h2> <h3>h3</h3> </div> .myheadercolor h1, .myheadercolor h2,.myheadercolor h3 {color: orange;} Link to comment Share on other sites More sharing options...
smus Posted October 18, 2018 Author Share Posted October 18, 2018 naive solution, because, hypothetically, headings might be scattered around the document. No, I was just wondering why developers invented such convenient thing, but did not apply it to tag names. Philosophical question Link to comment Share on other sites More sharing options...
dsonesuk Posted October 18, 2018 Share Posted October 18, 2018 As they are part of the same document, representing main title heading and sub headings of importance, No! not really, as they, would come under the same parent element. IF they were scattered anywhere, then they are not used as they were properly intended. Link to comment Share on other sites More sharing options...
Funce Posted October 18, 2018 Share Posted October 18, 2018 (edited) You'll need to do H1, h2, h3 and so on https://stackoverflow.com/questions/7539125/can-i-target-all-h-tags-with-a-single-selector Edited October 18, 2018 by Funce Link to comment Share on other sites More sharing options...
ishan_shah Posted June 27, 2019 Share Posted June 27, 2019 If you have only header tags in your HTML than you can use * as an universal selector. Or else you can give names if there are only few tags as you don`t want to give class to the all elements. Link to comment Share on other sites More sharing options...
shaili_shah Posted November 8, 2019 Share Posted November 8, 2019 universal selector apply style to all element so if you have another tag except h1,h2,h3 you must be apply style to parent class Link to comment Share on other sites More sharing options...
ishan_shah Posted November 22, 2019 Share Posted November 22, 2019 (edited) Hello @smus, Simply you can use the element name separated by a comma as a selector in CSS. Following is the example of multiple tags as a single selector. E.x. h1, h2, h3 { color:orange; } Edited November 22, 2019 by ishan_shah Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now