Forum How do I...?

class selector works, but id selector doesn't?

jean
Hi there

Why does this work:
a[name="tape_properties__table"] ~ table col:first-of-type { width: 5%; }


but this doesn't:
a#tape_properties__table ~ table col:first-of-type { width: 5%; }


This is for HTML like:
          <a name="tape_properties__table" id="tape_properties__table"></a>

          <table border="1">
            <colgroup>
              <col width="20%">


so both the ID and the NAME are present.
mikeday
We have had some issues with interactions between the name and id attributes before, and in general recommend using id when you can. However, I can't actually reproduce this problem. Are you able to simplify it a little bit, perhaps to a small document with an id selector that should change the color of some text, but fails to do so?
jean
My first attempt at reproducing fails .. I.e. the following works perfectly :?

<html>
    <head>
        <style>
            p#id ~ p { color: red }
        </style>
    </head>
    <body>
        <p id="id" name="name"></p>
        <p>asdf</p>
    </body>
</html>


I'll try again to reproduce, working backwards from a failing case, when I have some time ..
mikeday
I think that the name attribute is only treated specially on the <a> element, and it may also be affected by whether the document is parsed as XML or HTML.