Multiple ID instances

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • qwe

    Multiple ID instances

    More curiosity than a real problem, but...

    I've been abusing HTML ID attributes slightly.

    ..box {
    margin: 10px;
    }

    #red {
    background-color: #ff0000;
    }

    #green {
    background-color: #00ff00;
    }

    <div class="box" id="red"></div>
    <div class="box" id="green"></div>
    <div class="box" id="red"></div>

    To get a red box followed by a green box and another red box.

    HTML validators complain because id attributes are supposed to be unique,
    but the big three browser engines let me get away with it.

    What's the "right" way to do this? Should I just have boxred and boxgreen
    classes? That seems a little wasteful when I only want to change one
    property.

  • Steve Pugh

    #2
    Re: Multiple ID instances

    qwe <_12Rounds@yaho o.com> wrote:

    [color=blue]
    >I've been abusing HTML ID attributes slightly.
    >
    >.box {
    > margin: 10px;
    >}
    >
    >#red {
    > background-color: #ff0000;
    >}
    >
    >#green {
    > background-color: #00ff00;
    >}
    >
    ><div class="box" id="red"></div>
    ><div class="box" id="green"></div>
    ><div class="box" id="red"></div>
    >
    >To get a red box followed by a green box and another red box.
    >
    >HTML validators complain because id attributes are supposed to be unique,
    >but the big three browser engines let me get away with it.[/color]

    They let you get away with all sorts of things, but will they continue
    to do so in the next version?
    [color=blue]
    >What's the "right" way to do this? Should I just have boxred and boxgreen
    >classes? That seems a little wasteful when I only want to change one
    >property.[/color]

    Change red and green to classes and apply multiple classes to the
    divs. Some older browsers will not apply either class.

    <div class="box red"></div>
    <div class="box green"></div>
    <div class="box red"></div>

    Or use classes as you suggest but give the shared and differeing
    properties in different styles e.g.

    ..boxred, .boxgreen { margin: 10px; }
    ..boxred { background-color: #ff0000; }
    ..boxgreen { background-color: #00ff00; }

    Or set the background-color of .box to red and just have #green
    override it in the one exception.
    <div class="box"></div>
    <div class="box" id="green"></div>
    <div class="box"></div>

    The best solution will depend on you actual situation rather than on
    the simplified examples being used here.

    BTW you should always set a color when you set a background-color.

    Steve

    --
    "My theories appal you, my heresies outrage you,
    I never answer letters and you don't like my tie." - The Doctor

    Steve Pugh <steve@pugh.net > <http://steve.pugh.net/>

    Comment

    • qwe

      #3
      Re: Multiple ID instances

      On Tue, 05 Aug 2003 07:52:05 +0100, Steve Pugh <steve@pugh.net > wrote:
      [color=blue]
      >They let you get away with all sorts of things, but will they continue
      >to do so in the next version?[/color]

      Yes; as long as there is competition in the market, the browser that is
      least strict will have an edge.
      [color=blue]
      >.boxred, .boxgreen { margin: 10px; }
      >.boxred { background-color: #ff0000; }
      >.boxgreen { background-color: #00ff00; }[/color]

      I think that's exactly what I was looking for... thanks. The other examples
      were useful too.

      Comment

      • Headless

        #4
        Re: Multiple ID instances

        qwe <_12Rounds@yaho o.com> wrote:
        [color=blue]
        >.box {
        > margin: 10px;
        >}
        >
        >#red {
        > background-color: #ff0000;
        >}
        >
        >#green {
        > background-color: #00ff00;
        >}
        >
        ><div class="box" id="red"></div>
        ><div class="box" id="green"></div>
        ><div class="box" id="red"></div>
        >
        >To get a red box followed by a green box and another red box.
        >
        >HTML validators complain because id attributes are supposed to be unique,
        >but the big three browser engines let me get away with it.
        >
        >What's the "right" way to do this? Should I just have boxred and boxgreen
        >classes? That seems a little wasteful when I only want to change one
        >property.[/color]

        ..box{margin:10 px}
        ..red{backgroun d-color:#ff0000}
        ..green{backgro und-color:#00ff00}

        <div class="box red"></div>
        <div class="box green"></div>
        <div class="box red"></div>


        Headless

        --
        Email and filter list: http://www.headless.dna.ie/usenet.htm

        Comment

        • Chris Morris

          #5
          Re: Multiple ID instances

          qwe <_12Rounds@yaho o.com> writes:[color=blue]
          > On Tue, 05 Aug 2003 07:52:05 +0100, Steve Pugh <steve@pugh.net > wrote:[color=green]
          > >They let you get away with all sorts of things, but will they continue
          > >to do so in the next version?[/color]
          >
          > Yes; as long as there is competition in the market, the browser that is
          > least strict will have an edge.[/color]

          Yes, but which edge? Guessing the meaning of invalid code *wrongly*
          isn't going to do much for their reputation as a reliable UA.

          --
          Chris

          Comment

          • Alan J. Flavell

            #6
            Re: Multiple ID instances

            On Tue, Aug 5, Chris Morris inscribed on the eternal scroll:
            [color=blue]
            > Yes, but which edge? Guessing the meaning of invalid code *wrongly*
            > isn't going to do much for their reputation as a reliable UA.[/color]

            The problem here is that the kind of author who relies on browser
            guessing will optimise their page for the browser that does the most
            guessing (YKWIM), and then complain about all the others being
            "wrong".

            --
            "In the hardest of cases, I show them the W3C membership list: as
            soon as the customer sees that MS is a member, then everything the
            W3C says is good, and typically they even demand conformance with
            W3C written into the contract" - (Matthias Esken, freely translated)

            Comment

            • Chris Morris

              #7
              Re: Multiple ID instances

              qwe <_12Rounds@yaho o.com> writes:[color=blue]
              > On Tue, 5 Aug 2003 08:01:05 +0000 (UTC), "Jukka K. Korpela"
              > <jkorpela@cs.tu t.fi> wrote:[color=green]
              > >Really? Meanwhile on Earth, the versions of the most popular browsers have
              > >been getting _stricter_ in the last few years, both as regards to HTML and[/color]
              >
              > Yeah, I thought that would get a bite.
              >
              > Look at it like this. You're an end-user. Browser A renders your favourite
              > site perfectly, Browser B shows you a blank page. Which browser will you
              > use?[/color]

              Given that I switch browser based on what machine I'm currently using,
              I'd probably never have chosen it as a favourite site.
              [color=blue]
              > (Example off the top of my head: Netscape 4 is really picky about </td>
              > tags. Mozilla 1 will correctly render the page if you ignore them.)
              >
              > <table border="1">
              > <tr><td>1<td>3< tr><td>2<td>4
              > </table>[/color]



              End tags for <td> and <tr> are optional in HTML 4. Netscape 4 ignores
              the spec and goes wrong, Mozilla 1 follows the spec and gets it right.

              Your point?

              --
              Chris

              Comment

              • David Dorward

                #8
                Re: Multiple ID instances

                qwe wrote:
                [color=blue]
                > HTML validators complain because id attributes are supposed to be unique,
                > but the big three browser engines let me get away with it.
                >
                > What's the "right" way to do this? Should I just have boxred and boxgreen
                > classes? That seems a little wasteful when I only want to change one
                > property.[/color]

                Elements can have multiple classes.

                class="box red"

                Which would match .red { } AND .box { }

                --
                David Dorward http://david.us-lot.org/
                Which is stupider: Pop-up ads claiming they'll stop spam, or spam claiming
                it'll stop pop-up ads? -- Dork Tower

                Comment

                • Chris Morris

                  #9
                  Re: Multiple ID instances

                  qwe <_12Rounds@yaho o.com> writes:[color=blue]
                  > On 05 Aug 2003 10:47:13 +0100, in comp.infosystem s.www.authoring.stylesheets
                  > you wrote:[color=green]
                  > >qwe <_12Rounds@yaho o.com> writes:[color=darkred]
                  > >> (Example off the top of my head: Netscape 4 is really picky about </td>
                  > >> tags. Mozilla 1 will correctly render the page if you ignore them.)[/color][/color]
                  >[color=green]
                  > >http://www.w3.org/TR/html401/struct/....html#h-11.2.5
                  > >
                  > >End tags for <td> and <tr> are optional in HTML 4. Netscape 4 ignores
                  > >the spec and goes wrong, Mozilla 1 follows the spec and gets it right.[/color]
                  >
                  > Hmm... you could be right. What about XHTML 1.0? I was under the impression[/color]

                  Obviously they're both required in XHTML 1.0, but since Netscape 4
                  predates XHTML this comparison is beginning to get silly.

                  To bring things slightly back on topic with stylesheets, closing all
                  non-empty elements is very good to avoid Netscape 4 CSS confusion.
                  [color=blue]
                  > it was an XML application, though I confess I didn't test Mozilla's reaction
                  > with the correct doctype in place. One moment...[/color]

                  XML Parsing Error: mismatched tag. Expected: </td>.
                  Location: http://dinopsis/~cim/xhtmltest
                  Line Number 9, Column 8:
                  </table>
                  -------^

                  Of course, that was sending it with the application/xhtml+xml content-type.

                  Sending it as text/html it isn't surprising it treats it as HTML, most
                  browsers not going to the trouble of downloading (or otherwise
                  obtaining) the DTD and performing a validation before displaying the
                  page.
                  [color=blue]
                  > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                  > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                  > <html>
                  > <body>
                  > <table border="1">
                  > <tr><td>1<td> 3
                  > <tr><td>2<td> 4
                  > </table>
                  > </body>
                  > </html>
                  >
                  > renders as (un?)expected in Mozilla 1.3, IE 6.02 and Opera 7.0, all on Win.[/color]

                  Sent as application/xhtml+xml, IE offered to save
                  it to disk, and Opera did something similar to Mozilla (except the
                  error report was a little more helpful).
                  [color=blue]
                  > Possibly I'm missing a "be really anal" switch in one or another of them,
                  > but even if it exists then it's off by default and my point still stands -
                  > browser vendors place "what the author meant to say" over "what the author
                  > really said".[/color]

                  TelepathicML, excellent. It's when they get it wrong that the
                  problems come in. (previous comments about a certain application
                  'training' authors for its bugs accepted, though)
                  [color=blue]
                  > Now I come to think about it, that may even be the Right Thing
                  > from a usability POV - hmm.[/color]

                  There is a principle of 'be conservative in what you send, be liberal
                  in what you accept', but the problem is that if you're the wrong
                  liberal things get even worse than if you'd rejected it initially.
                  [color=blue]
                  > I just don't see a time when a major browser will refuse to render <br> or
                  > <hr> in an XHTML doc.[/color]

                  XML Parsing Error: mismatched tag. Expected: </br>.
                  Location: http://dinopsis/~cim/xhtmltest
                  Line Number 9, Column 3:

                  The future is now?

                  --
                  Chris

                  Comment

                  • qwe

                    #10
                    Re: Multiple ID instances

                    On 05 Aug 2003 12:15:30 +0100, Chris Morris <c.i.morris@dur ham.ac.uk> wrote:
                    [color=blue]
                    >Obviously they're both required in XHTML 1.0, but since Netscape 4
                    >predates XHTML this comparison is beginning to get silly.[/color]

                    Yup.
                    [color=blue]
                    >Sending it as text/html it isn't surprising it treats it as HTML, most
                    >browsers not going to the trouble of downloading (or otherwise
                    >obtaining) the DTD and performing a validation before displaying the
                    >page.[/color]

                    Interesting. I suppose there are no hard and fast rules about what to do
                    when the content-type and doctype disagree, because they're in seperate
                    specs.
                    [color=blue]
                    >There is a principle of 'be conservative in what you send, be liberal
                    >in what you accept', but the problem is that if you're the wrong[/color]

                    I was thinking of the law of least surprise, but that fits too.
                    [color=blue]
                    >liberal things get even worse than if you'd rejected it initially.[/color]

                    Unless you hold 90% of the market, of course... then you become a de facto
                    standard.

                    The rest snipped because I think you've proved your points pretty
                    succesfully.

                    Comment

                    • Chris Morris

                      #11
                      Re: Multiple ID instances

                      qwe <_12Rounds@yaho o.com> writes:[color=blue]
                      > On 05 Aug 2003 12:15:30 +0100, Chris Morris <c.i.morris@dur ham.ac.uk> wrote:[color=green]
                      > >Sending it as text/html it isn't surprising it treats it as HTML, most
                      > >browsers not going to the trouble of downloading (or otherwise
                      > >obtaining) the DTD and performing a validation before displaying the
                      > >page.[/color]
                      >
                      > Interesting. I suppose there are no hard and fast rules about what to do
                      > when the content-type and doctype disagree, because they're in seperate
                      > specs.[/color]

                      Try Content-type: text/plain for an example.

                      Any standards-compliant browser will go for the content type and if
                      the text document sent happens to contain a doctype and some HTML
                      elements, so what. The HTTP rules say content-type headers are the
                      ones to go for in determining what the document is.

                      Any horribly broken operating system component will go for the fact
                      that it 'looks a bit like a HTML document' over the content type, and
                      all sorts of things can go interestingly wrong, of course.

                      --
                      Chris

                      Comment

                      • Alan J. Flavell

                        #12
                        OT W3C conformance, was Re: Multiple ID instances

                        On Tue, Aug 5, Chris Morris inscribed on the eternal scroll:
                        [color=blue]
                        > Any horribly broken operating system component will go for the fact
                        > that it 'looks a bit like a HTML document' over the content type, and
                        > all sorts of things can go interestingly wrong, of course.[/color]

                        As far as I could determine, it took no more than the character string
                        <TITLE>, close enough to the start of the text/plain document, to
                        throw that thing into RFC-violation mode. Absolutely no need to say
                        <HTML> anywhere.

                        I read somewhere in their KB that they claimed to have a fix for
                        IE5.*, but it's not installed by default: I installed it some time
                        back, and it didn't work.

                        See: http://support.microsoft.com/default...b;en-us;164672

                        which in mid-1999 (that was 4 years ago, right?) said:

                        Microsoft has confirmed this to be a problem with Microsoft Internet
                        Explorer version 3.0 or above. We are researching this problem and
                        will post new information here in the Microsoft Knowledge Base as it
                        becomes available.

                        Erm, yes. Actually, a fellow usenaut with a sense of history points
                        out that the vulnerability which MS were going to create several years
                        later, was described, and recipes given for exploiting it, in IETF
                        discussions long before MS decided to get involved in the Internet.

                        RFC2616 makes recommendations based on that earlier understanding. Yet
                        still MS behave as if they don't understand the problem that they've
                        created, and can't solve it other than by applying sticky-tape
                        solutions one by one as each exploit appears, rather than addressing
                        one of the fundamentals by implementing this mandatory requirement of
                        RFC2616.

                        Well, then there's

                        and


                        Are they getting there? I tried IE6 and it still doesn't work,
                        although its wrong behaviour is slightly different from the previous
                        wrong behaviour. Sigh.

                        Comment

                        • Stephen Poley

                          #13
                          Re: Multiple ID instances

                          On Tue, 05 Aug 2003 09:32:08 +0100, qwe <_12Rounds@yaho o.com> wrote:
                          [color=blue]
                          >Look at it like this. You're an end-user. Browser A renders your favourite
                          >site perfectly, Browser B shows you a blank page. Which browser will you
                          >use?[/color]

                          One starts with a browser, then looks at sites. If site A is unreadable
                          in my browser, I go to site B instead (unless site A has some *really*
                          important content that I simply cannot get anywhere else - doesn't
                          happen often.)

                          [color=blue]
                          >(Example off the top of my head: Netscape 4 is really picky about </td>
                          >tags. Mozilla 1 will correctly render the page if you ignore them.)
                          >
                          ><table border="1">
                          > <tr><td>1<td>3< tr><td>2<td>4
                          ></table>[/color]

                          That's a poor example though - omission of </td> is valid, and Netscape
                          4 is broken. The issue here is error-correction of invalid HTML.

                          --
                          Stephen Poley


                          Comment

                          Working...