views:

143

answers:

4

Why do most developers consider the W3C box-model to be better than the box-model used by Internet Explorer?

I know it's very frustrating developing pages that look the way you want them on Internet Explorer, but I find the W3C box-model to be counter-intuitive. For example, if margins, padding, and border were factored into the width, I could assign fixed width values for all my columns without having to worry about how many columns I have and what changes I make to my padding and margins.

Under W3C box model I have to worry about how many columns I have, and develop something akin to a mathematical formula to calculate my values. Changing them would nightmarish, especially for complex layouts. My novice opinion is that it's more restrictive. Consider this small frame-work I wrote:

#content {
margin:0 auto 30px auto;
padding:0 30px 30px 30px;
width:900px;
}
    #content .column {
        float:left;
        margin:0 20px 20px 20px;
    }
    #content .first {
        margin-left:0;
    }
    #content .last {
        margin-right:0;
    }   
        .width_1-4 {                    
            width:195px;                
        }                       
        .width_1-3 {
            width:273px;                
        }
        .width_1-2 {
            width:430px;
        }
        .width_3-4 {
            width:645px;
        }
        .width_1-1 {
                    width:900px;
        }

These values I have assigned here will falter unless there are three columns, and thus the margins at 0(first)+20+20+20+20+0(last). It would be a disaster if I wanted to add padding to my columns too, as my entire setup would have to be re calibrated. Now imagine if column width incorporated all the other elements, all I would need to do is change one associated value, and I have my layout. I'm less criticizing it and more hoping to understand why it's better, or why I'm finding it more difficult.

Am I doing this whole thing wrong? I don't know very much about this topic, but it seems counter intuitive to use W3C's box-model. Some advice would be really appreciated.

Thanks

+5  A: 

Personally, I prefer -to my occasional shame- IE's box-model. As noted by the OP it seems to make more sense to have a pre-defined width from which margin, padding and border-width are subtracted, than to have a width to which these are then added.

On the other hand, I can work with both models quite happily, all I really want is consistency between implementations, whichever implementation is chosen.

David Thomas
Once I got into accidentally coding for IE's box model and became a fan of it. That's the perfect logic for a box. Ask W3C to run a container shipping firm, and it's dead in a week.
Nirmal
@Nirmal, yup. I think that's basically the same argument that PPK makes, at the Quirksmode links. I was going to quote it but, by the time I'd remembered where it was, @Anurag and, I think, @Andy E. had already linked/quoted, so it seemed redundant. I accept that the spec is always going to be *arbitrary*, but it would be nice for it to be *rational* as well.
David Thomas
@Nirmal, not to mention that by the time they've agreed the shipping manifest, the loading-orders, the schedule and the route you'd be looking at something like 2025 to get the book you ordered in 2004... =)
David Thomas
+4  A: 

One word answer - -box-sizing

You choose how you want your box model to work.

Anurag
There's still so much css that I never even *suspected* might exist... +1 for that (now-bookmarked) link =)
David Thomas
I am in the same boat. Btw, this template layout module (part of CSS3) is the coolest thing I've ever seen for CSS.http://www.w3.org/TR/2009/WD-css3-layout-20090402/
Anurag
@Anurag, I'm suddenly even more optimistic for CSS3. Here's hoping it's implemented *at least* as soon as html5... =)
David Thomas
@ricebowl Seeing the way w3 works has reaffirmed my faith in committees :) .. they're doing some awesomely brilliant stuff
Anurag
Hmmm...seeing the way that the W3 mostly-works affirms *my* faith in committees. Though I'll hand it to them, and happily, the more I read, and hear, about html 5 and css 3 the happier I become =)
David Thomas
Thanks everyone for your input. But specifying my own box-sizing does not work in internet explorer 8 (ironically it insists on using the W3C model now) unless I remove the !Doctype from the page header. I don't know if doing so has a negative impact on the page.
Mel
My bad, only when IE8 is in "compatibility mode," which, if I understand this correctly, is emulating IE7?
Mel
I don't have access to IE, but are you using `-ms-box-sizing` or `box-sizing`? I thought browsers were still waiting for the spec to finalize before they remove the `-webkit`, `-moz` and `-ms` prefixes.
Anurag
I was using -ms-box-sizing, which did not work. I just added box-sizing, and that works in IE8. This is strange though: If CSS3 is not supported yet, and the whole purpose of the prefixes is to support something that has not been released yet, why does IE8 work in the opposite? Or am I getting this horrible wrong?
Mel
@Mel, welcome to web-development, young Padewan. Eventually it stops hurting...Promise! =)
David Thomas
lol @ricebowl, web development is not a science, nor an art. it's embracing the philosophy that there is chaos in this world and abandoning all libraries that try to abstract it away. A true ninja will always code fearlessly `if(IE5) {..} else if(IE6) {..} else if(IE6.1) {..} else if(FF1.5.2) {..}` and so on
Anurag
To be honest with you, I'm really frustrated. We have so much technology today, yet creating a CSS layout that makes senses hardly involves any sensible code. Every layer of complexity makes it a bigger pain!
Mel
+1  A: 

It is not so much an issue of which is better or worse, but which follows the standard from an accepted organization and which not..

On the other hand of your problems would be someone who wants his text wrapped inside a 300px container, which has a distance of 10 pixels from the next one.. Now you would have to make the same calculations as your example in order to calculate the width.. it is a case of how you view the same problem..

Gaby
"Luke, you're going to find that many of the truths we cling to depend greatly on our own point of view." =b
David Thomas
@ricebowl, lol. Deep runs within you the force..
Gaby
+5  A: 

Not everyone considers it to be better. To extract a quote from Quirksmode.

Personally I find W3C's box model counter-intuitive. To quote myself:

Logically, a box is measured from border to border. Take a physical box, any box. Put something in it that is distinctly smaller than the box. Ask anyone to measure the width of the box. He'll measure the distance between the sides of the box (the 'borders'). No one will think of measuring the content of the box.

Web designers who create boxes for holding content care about the visible width of the box, about the distance from border to border. The borders, and not the content, are the visual cues for the user of the site. Nobody is interested in the width of the content.

I agree, the border-box model makes more sense (at least, it does to me). The reason the CSS3 box-sizing property became defined was disputes over the current box model

Andy E