Search code examples
htmlcsspositioncss-position

Issues with html divs not containing what they should


https://i.sstatic.net/zg35O.png

My div id="topcol" is showing a far smaller area than it should. It's supposed to include the 4 "options". The options are relative so that the option titles can be absolute and overlay the images in each option.

I realise this is probably a really basic mistake but I've been struggling with it for hours

html:
<div id="cols">
            <div id="topcol">
                <h1 id="content_title">BrightWell Smart Page Services</h1>
                <div class="options" id="op1" name="General Links"><img class="optionicons" src="generalLinks.jpg"/><span class="optiontitle">General Links</span></div>
                <div class="options" id="op2" name="Useful Online Tools"><img class="optionicons" src="Toolbox.jpg"/><span class="optiontitle">Useful Online Tools</span></div>
                <div class="options" id="op3" name="IT Links"><img class="optionicons" src="ITSupport.jpg"/><span class="optiontitle">IT Links</span></div>
                <div class="options" id="op4" name="Utility"><img class="optionicons" src="utility.jpg"/><span class="optiontitle">Utility</span></div>
            </div>
            <div id="botcol">
                <div id="infopanel">

                </div>
            </div>
        </div>

css:
html    {
    font-family: 'FuturaW01-LightCondense 774878',Helvetica,Arial,sans-serif;
    font-weight: lighter;
}
#cols {
    z-index:1;
    position: absolute;
    top:0;
    left:0;
    height:100%;
    width:100%;
}
#topcol {
    height:auto;
    width:100%;
}
#botcol {
    width:100%;
}

#content_title {
font-size: 32px;
line-height: 1.2;
}
.options {
    margin-left:2.5%;
    margin-right:2.5%;
    height:30%;
    width:19%;
    float:left;
    border: black solid 1px;
    position:relative;
}
#op1{

}
#op2{

}
#op3{
    float:right;
}
#op4{
    float:right;
}
.optiontitle {
    color: blue;
    position:absolute;
    top:0;
    left:0;
    text-align:center;
    font-size:200%;
    width:100%;
}
.optionicons {
    height:100%;
    width:100%;
}
#infopanel {
    width:100%;
    height:100%;
}

Solution

  • Since you float the children divs, the are removed from the normal flow and the parent (topcol) collapses as if they weren't there. You can add overflow:auto to your #topcol rules to restore the behavior you're after.