Results 1 to 4 of 4

Thread: div inside fieldset doing weird things

  1. #1
    Join Date
    Jun 2008
    Posts
    192
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default div inside fieldset doing weird things

    I'm encountering some really weird behavior with a div inside a fieldset. Please have a look at this code:

    Code:
    <html>
    <head></head>
    <body>
    
    <fieldset style="width: 50%;">
    <legend>legend</legend>
    <div style="background-color: blue; display: table-cell; width: 50%;">
    This is a fieldset.
    </div>
    </fieldset>
    
    </body>
    </html>
    The div is definitely not 50% of the fieldset in width even though it's set to be.

    What's even weirder is that if I set the div to be 100% width, it takes up even less space.

    Does anyone know what's going on here?

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    The div is actually doing exactly what you have told it to because you have set its display to table-cell. I'm not sure why you're doing that but it might help if you read the specs to understand what is happening - see the section on Anonymous Table Objects, where missing container/parents are being generated around the lone table-cell http://www.w3.org/TR/CSS2/tables.html#anonymous-boxes
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Jun 2008
    Posts
    192
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    The quote from that site that seems most relevant to me is this:

    "1.For each 'table-cell' box C in a sequence of consecutive internal table and 'table-caption' siblings, if C's parent is not a 'table-row' then generate an anonymous 'table-row' box around C and all consecutive siblings of C that are 'table-cell' boxes."

    So it's creating a table-row div around my table-cell div. (Would it then create a table div around the table-row div?)

    But I'm still not understanding why the width doesn't look like 50% of the fieldset, unless the table-row div is some odd arbitrary percentage of the width of the fieldset, but why? Furthermore, that doesn't explain why setting the width to 100% makes it even shorter.

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    The specs are your friend and you can find out all you need to know there : http://www.w3.org/TR/CSS2/tables.htm...d-table-layout

    Also look into default element padding and the effect on the box model
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

Similar Threads

  1. Div in a fieldset
    By Webiter in forum CSS
    Replies: 2
    Last Post: 07-02-2012, 04:06 PM
  2. Replies: 0
    Last Post: 04-04-2009, 07:48 AM
  3. Weird ul behavior inside p
    By genia in forum CSS
    Replies: 10
    Last Post: 01-05-2009, 09:45 PM
  4. php processing script doing weird things
    By stealthmode666 in forum PHP
    Replies: 4
    Last Post: 12-21-2008, 02:10 PM
  5. fieldset tag
    By insanemonkey in forum HTML
    Replies: 4
    Last Post: 10-11-2007, 08:01 PM

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
  •