How to style CSS role

Css

Css Problem Overview


In the following HTML

<div id="content" role="main">

the id can be accessed through #content in CSS. How do I access role="main".

Css Solutions


Solution 1 - Css

Use CSS attribute selectors:

https://developer.mozilla.org/en-US/docs/CSS/Attribute_selectors

e.g.:

div[role=main]

Solution 2 - Css

The shortest way to write a selector that accesses that specific div is to simply use

[role=main] {
  /* CSS goes here */
}

The previous answers are not wrong, but they rely on you using either a div or using the specific id. With this selector, you'll be able to have all kinds of crazy markup and it would still work and you avoid problems with specificity.

[role=main] {
  background: rgba(48, 96, 144, 0.2);
}
div,
span {
  padding: 5px;
  margin: 5px;
  display: inline-block;
}

<div id="content" role="main">
  <span role="main">Hello</span>
</div>

Solution 3 - Css

Accessing it like this should work: #content[role="main"]

Solution 4 - Css

Sure you can do in this mode:

 #content[role="main"]{
       //style
    }

http://www.w3.org/TR/selectors/#attribute-selectors

Solution 5 - Css

we can use

 element[role="ourRole"] {
    requried style !important; /*for overriding the old css styles */
    }

Solution 6 - Css

Solution 7 - Css

please use :

 #content[role=main]{
   your style here
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlaggingreflexView Question on Stackoverflow
Solution 1 - CsssyncView Answer on Stackoverflow
Solution 2 - CssPatrickView Answer on Stackoverflow
Solution 3 - CsspduView Answer on Stackoverflow
Solution 4 - CssAlessandro MinoccheriView Answer on Stackoverflow
Solution 5 - CssshrawanView Answer on Stackoverflow
Solution 6 - CssChandra Sekhar WalajapetView Answer on Stackoverflow
Solution 7 - CssSaeedView Answer on Stackoverflow