How to style CSS role

前端 未结 7 622
庸人自扰
庸人自扰 2021-02-03 16:12

In the following HTML

the id can be accessed through #content in CSS. How do I access

相关标签:
7条回答
  • 2021-02-03 16:57

    please use :

     #content[role=main]{
       your style here
    }
    
    0 讨论(0)
  • 2021-02-03 16:58

    we can use

     element[role="ourRole"] {
        requried style !important; /*for overriding the old css styles */
        }
    
    0 讨论(0)
  • 2021-02-03 17:06

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

    0 讨论(0)
  • 2021-02-03 17:07

    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>

    0 讨论(0)
  • 2021-02-03 17:08

    Sure you can do in this mode:

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

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

    0 讨论(0)
  • 2021-02-03 17:09

    follow this thread for more information

    CSS Attribute Selector: Apply class if custom attribute has value? Also, will it work in IE7+?

    and learn css attribute selector

    http://www.w3schools.com/css/css_attribute_selectors.asp

    0 讨论(0)
提交回复
热议问题