Style HTML element based on its title using CSS

前端 未结 5 1718
慢半拍i
慢半拍i 2021-01-08 01:33

Is it possible to apply a style to an HTML element using only its title as a unique identifier? For example:


                      
相关标签:
5条回答
  • 2021-01-08 01:47

    Although it is possible, using attribute selectors (see http://www.w3.org/TR/CSS2/selector.html#attribute-selectors ) Internet Explorer 6 does not support it (see http://kimblim.dk/css-tests/selectors/ )

    An example from the W3C site: H1[title] { color: blue; }

    0 讨论(0)
  • 2021-01-08 01:54

    What you are looking for is css attribute selectors:

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

    a[title] { ... }

    0 讨论(0)
  • 2021-01-08 01:59

    Yes you can:

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

    You would say A[title="MyTitle] I believe.

    0 讨论(0)
  • 2021-01-08 02:10

    It sure is, using what's called attribute selectors; these are part of CSS2. In your particular case, you'd use:

    div.my_class a[title="MyTitle"] { color: red; }
    

    You can read more about attribute selectors here: http://www.w3.org/TR/CSS2/selector.html#attribute-selectors

    0 讨论(0)
  • 2021-01-08 02:13

    CSS specifications identify a number of "selectors" that may help you here. For example, you could apply a rule such as the following:

    .my_class a[title="MyTitle"]
    {
       ...
    }
    

    You can see a detailed specification of CSS "selectors" here:

    http://www.w3.org/TR/2001/CR-css3-selectors-20011113/

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