Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS 50% plus 50% equals 105%?

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #33968
    WhiteRau
    Member

    hey gang:

    here’s the relevant HTML and CSS first:

    —HTML:





    Bad CSS Math





    like a fat kid on a cupcake

    Copyright © 2011 MoDUS



    —CSS:

    body {
    background: url(../_img/body_bg.gif);
    color: #ccffff;
    line-height: 1.0em;
    font-style: normal;
    font-weight: normal;
    }

    article, aside, figure, footer, header, nav, section {
    display: block;
    }

    footer {
    margin: 0 auto 20px;
    min-height: 120px;
    width: 930px;
    }

    #quote {
    font-family: "HeroidRegular", Tahoma, Geneva, sans-serif;
    padding: 10px;
    width: 50%;
    float: left;
    }

    #copy {
    padding: 10px;
    text-align: right;
    width: 50%;
    float: right;
    }

    for some reason i cannot determine, this produces this lovely effect:

    http://img21.imageshack.us/img21/6329/csshalfsiesproblem.jpg

    what the heck is happening!? i checked margins, padding, &c and nothing appears to be out of order. when i hover the mouse over the design side, the popups are accurate!! i am totally stumped.

    WR!

    #85205
    TheDoc
    Member

    The padding on your quote and copy divs will cause this.

    #85207
    TheDoc
    Member

    Example:

    30px Width + 20px Padding = 70px Actual Width
    50% Width + 10px Padding = 50%+20px Actual Width

    #85208
    WhiteRau
    Member

    yeah. dammit. i thought the percentage automatically compensated. i guess not. thanks guys. i will now go bash my buddy’s head with a Nerf brick…

    WR!

    #85210

    @WhiteRau @TheDoc you could actually use the CSS box-sizing property to force the padding inside the box rather than outside. It will work in all browsers other than IE7 (see: http://caniuse.com/#search=box-sizing). You would use the following code:

    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;

    See here for more details: http://jhop.me/css/css3/the-css3-box-sizing-concept-a-solution-to-a-longstanding-problem

    I have also done up a quick fiddle to help illustrate: http://jsfiddle.net/sl1dr/Aw92J/

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘CSS’ is closed to new topics and replies.