SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why put label/input combo within divs?

    hi,

    i think that the css related featured thread are very interesting. Even if it might seem basic at first sight (sometimes), it's actually asks deeper questions than what meets the eyes.

    For example, in a recent thread, a few members suggested to put each label/input combo within a form.

    I don't understand why it is a good practice. Aren't divs supposed to separate a page into different areas? It seems to me that a form can be considered as a single area (<form> </form>) and I can't see why putting divs in the middle of it is good.

    Why not use paragraphs? Or why not style the label and input elements to achieve what is wanted?

    I am probably missing something and I really hope that a few real life examples will enlight me.


  2. #2
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DIV is semantically neutral - it doesn't really have a set purpose like "separating a page into different areas", you can use it for whatever you want.

    I think that the main reason some developers like to wrap each label/input pair in a <div> is so that they can exercise greater control over the layout, and also so that when displayed unstyled the form elements don't all run together into a big mishmash of text and boxes.

    As I said in the thread you linked, I prefer to use <br /> as it has the same effect and uses a lot less bytes.

  3. #3
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but <br /> is not semantic in this context.

    Still, why not use a paragraph?

    What can do a div that the styling of label/input combos can't?

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A DIV is a division. It can be 'large' (like a section of a page) or small (like a couple of elements). It groups things together.

    DIVs for enclosing a LABEL and an INPUT in a FORM is useful when you float the LABELs so that the INPUTs line up. You can then set clear:both on the DIVs to avoid weird results in IE.

    If you consider a label and an input field to be a paragraph of text, by all means mark it up as one. For me, a paragraph is one or more sentences that belong together.
    Birnam wood is come to Dunsinane

  5. #5
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jjshell
    but <br /> is not semantic in this context.
    Yes it is - I want a <br>eak between each label/input pair, so I use the correct tag.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •