tags:

views:

39

answers:

4
+1  Q: 

Divs width problem

My problem is that ratio of width/height (for div with id="wrapper", different is huge) isn't the same on Chrome, Mozilla and IE (IE looks like refuse attribute for heigt at all). Any help, I need two divs fixed size, one beside other .

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>

        <style type="text/css">

            div#wrapper {
                width: 1000px;
                width:700px;
                margin-left:auto;
                margin-right:auto;
                overflow: hidden;
            }
            div#left {
                width: 80%;
                height: 80%;
                min-height: 80%;
                float: left;
                background-color: #DFDFDF;
                border-left-width:2px;
                border-left-style:solid;
                border-left-color:#606060;
                border-bottom-width:2px;
                border-bottom-style:solid;
                border-bottom-color:#606060;
                border-top-width:2px;
                border-top-style:solid;
                border-top-color:#606060;
            }
            div#right_up {
                width: 19%;
                height: 80%;
                min-height: 80%;
                float: left;
                background-color: whitesmoke;
                border-top-width:2px;
                border-top-style:dashed;
                border-top-color:#FF2A2A;
                border-right-width:2px;
                border-right-style:dashed;
                border-right-color:#FF2A2A;
                border-left-width:2px;
                border-left-style:solid;
                border-left-color:whitesmoke;
            }


        </style>
    </head>
    <body id="body"">
        <div id="wrapper">
            <div id="left">
                         REFERENCE:

            </div>
            <div id="right_up">

            </div>

        </div>
    </body>
</html>
+1  A: 

First of all you cannot use percentage heights on floated elements.

Second, I see no height set on the wrapper div

FutureKode
Sorry, my mistake.
Rebecca
A: 

Make sure that your code validates: http://validator.w3.org/ . Fixing the little errors it find will remove a lot of variance between browsers.

For instance, you've specified the width attribute twice for #wrapper, which doesn't make any sense.

bemace
A: 

Hey Rebecca and welcome to SO! :)

First of all, I don't think you could ever get mixed measurements units act the way you want. You have divs width in percentages and border width in pixels, basically you're hoping that 1% will never mean more than 2px for the wrapper width.

Let's take it step by step. First of all, you have 2 widths for the wrapper div. The second will overwrite the first and you'll end up with a width of 700px. That's very little, you should reconsider to a width of 960px or a max. of 990px (which assures you won't have an horizontal scrollbar on 99.9% of the screen resolutions today.

Let's rewrite that to:

div#wrapper {
    width: 700px; /* 700 to stick to your design */
    margin: 0 auto; /* which is basically the same as you have, but in one property, not two */
    overflow: hidden;
}

div#left {
    width: 558px; /* 80% of 700px (wrapper div) minus the border width. It will never change so there's no need to set it in percentages */ 
    height: 80%; /* height will overwrite min-height on FF for example. Also, min-height doesn't work in IE, setting a fixed height might be the best way to go */
    min-height: 80%;
    float: left;
    background-color: #DFDFDF;
    border: 2px solid #606060; /*set a border all over the div */
    border-right: 0; /* and remove the right border */
}

div#right_up {
    width: 140px; /* 20% of 700px */
    height: 80%; /* same height problem as you have for the other div here */
    min-height: 80%;
    float: right; /* float right, not left like the other one */
    background-color: whitesmoke; /* please set colors in hex, not like this */
    border: 2px dashed #FF2A2A;
    border-left: 2px solid whitesmoke; /* again, colors in hex please */
    border-bottom: 0;
}

Also, add a div with class clear in the markup like this:

<div id="wrapper">
    <div id="left">
        REFERENCE:
    </div>
    <div id="right_up">

    </div>
    <div class="clear"></div>
</div>

And add a class definition in the css like this:

.clear {
    clear: both;
}

The last advice is to allways put your CSS in an external stylesheet and reference it in your page in the head section of the HTML like this:

<link rel="stylesheet" type="text/css" href="path/to/style.css">

Good luck!

Claudiu