Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS positioning, need some advice

Here is my HTML code

<div id="container">
        <div id="topleft"></div>
        <div id="topright"></div>
        <div id="bottomleft"></div>
        <div id="bottomright"></div>
    </div>

Here is my css code

#container{
    width: 400px;
    height: 400px;
    background-color: red;
    margin: 0 auto;

}

#topright{
    width: 50px;
    height: 50px;
    background-color: black;
    position: relative;
    top:0px;
    right:0px;
}
#topleft{
    width: 50px;
    height: 50px;
    background-color: black;
    position:relative;
    top:0px;
    left:350px;
}

#bottomright{
    width: 50px;
    height: 50px;
    background-color: black;
    position: relative;
    top:250px;
    right:0px;
}
#bottomleft{
    width: 50px;
    height: 50px;
    background-color: black;
    position:relative;
    top:250px;
    left:350px;
}

Here is output http://s23.postimg.org/dhgy9mpq3/image.png

What I need to obtain, is that all 4 black square to be positioned in the corner of the red square like in this image, what should i change or add in code? THX http://postimg.org/image/r5kv15l5v/

like image 411
Chris Avatar asked Dec 03 '25 22:12

Chris


1 Answers

Add position:relative to #container and position:absolute to inner divs.

You can combine common properties with comma, like

#bottomright,#bottomleft{css properties}

CSS:

#container {
    position: relative;
}
#container > div {
    width: 50px;
    height: 50px;
    background-color: black;
    position: absolute;
}
#bottomright, #bottomleft {
    bottom:0;
}
#topright, #topleft {
    top:0;
}
#bottomleft, #topleft {
    left:0;
}
#bottomright, #topright {
    right:0;
}

DEMO here.

like image 66
codingrose Avatar answered Dec 06 '25 14:12

codingrose