<br /> or <div /> with old browsers...

Discussion in 'HTML & Website Design' started by winterheat, Jun 18, 2007.

  1. #1
    so i am starting to use more of <br /> and <div style="clear: both" /
    >...
    which is the XHTML style...

    now, won't those actually confuse the old browsers? for example,
    will the old browser treat the "div" as not closing, and so everything
    after the div will be treated as part of that div?
     
    winterheat, Jun 18, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    krt, Jun 18, 2007 IP
  3. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #3
    You meant </div> ?
     
    it career, Jun 19, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Umm... no. If you look at the first post again, there is a code written like so:
    <div style="clear: both" />
    Code (markup):
    Ignoring the style attribute, that is <div />.

    I was asking why that instead of a more compatible <div></div>
     
    krt, Jun 19, 2007 IP
  5. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well for starters, DIV has an explicit closing tag, so you should be using it to begin with. Self-closing tag styles are only meant for those elements that don't have them (such as BR, HR, IMG, INPUT, and so forth).
     
    Dan Schulz, Jun 19, 2007 IP
  6. winterheat

    winterheat Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i see... so for elements with a closing tag, do not self close it unless you know the audience will be using XHTML browser...

    so for <br />, the older browsers all interpret it as <br something_unknown> and therefore <br>? (kind of like <p foobar="abc"> will be taken as <p>)
     
    winterheat, Jun 19, 2007 IP
  7. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Dan Schulz, Jun 19, 2007 IP
  8. Will Morgan

    Will Morgan Peon

    Messages:
    70
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Talking of which, if you'd really like to be all XML style, then I believe the MIME type is application/xml+xhtml.

    Anyway, my preferred method is a <hr style="clear: both;" /> or using a <br style="clear: both;" /> since divs are meant to be used for page sections or divisions. Technically it's a case of semantics: I use hr when I feel I need to indicate a separation in the page. I also use it to keep the page useful in browsers that cannot interpret CSS.

    Also, you're better off just making a class called .clear with those attributes, it'll save you a bit of and keep you from using inline CSS, which isn't that great.
     
    Will Morgan, Jun 19, 2007 IP
  9. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #9
    And <br /> is meant to be a line break, not a float clearing device. I hardly ever use line breaks except when using poetry (haikus are a popular example) or forcing label/input fields onto new lines (just two examples, others include addresses for instance).

    I NEVER use line breaks to clear floats. Just clear the element that follows the floated one.
     
    Dan Schulz, Jun 19, 2007 IP
  10. winterheat

    winterheat Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
     
    winterheat, Jun 19, 2007 IP
  11. Will Morgan

    Will Morgan Peon

    Messages:
    70
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Yup, or that. But when there's nothing else to follow...

    Legacy ones so it seems. You'll probably need to add display: block; to make it fully effective.
     
    Will Morgan, Jun 19, 2007 IP
  12. winterheat

    winterheat Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    i wonder is the display: block to start a new line? i thought by default div will start a new line, thus moving the flow beyond the floated element.

    hm... maybe the most effective way can be

    <div style="clear: both; visibility: hidden">ha</div>
    just so that if some brower doesn't move the flow when there is nothing to display.
     
    winterheat, Jun 19, 2007 IP