Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a background color not overlap a border?

Tags:

html

css

im new to this site, and html/css aswell. Im trying to make some simpel stuff here, but im already stuck at this.

Please have a look at this: http://jsfiddle.net/SoronSR/u6GEh/

HTML:

<body>
<div id="container">
    <div id="column1-wrap">
        <div id="column1">Column 1</div>
    </div>
    <div id="column2">Column 2</div>
    <div id="clear"></div>
</div>
</body>

CSS:

#container {
border:5px solid #990000;
border-radius:10px;
}
#column1-wrap {
    float: left;
    width: 100%;
}
#column1 {
    background-color: cyan;
    margin-right: 200px;
}
#column2 {
    background-color: lime;
    float: left;
    width: 200px;
    margin-left: -200px;
}
#clear {
    clear: both;
}

The background color is overlapping the border at the edges. I want the background color to stay within the border. Can anyone help me with this?

like image 581
user3623414 Avatar asked May 10 '14 14:05

user3623414


People also ask

Does background color affect margin?

Styling of an element such as background color does not affect the margin. Padding is affected by the styling of an element, such as background color.


1 Answers

Simply add overflow:hidden to #container

Demo Fiddle

Note you can also accomplish what you want in a far simpler way:

Demo Fiddle

HTML

<div id="container">
    <div id="column2">Column 2</div>
    <div id="column1">Column 1</div>
</div>

CSS

#container {
    border:5px solid #990000;
    overflow:hidden;
    border-radius:10px;
}
#column1 {
    background-color: cyan;
    overflow:hidden;
}
#column2 {
    background-color: lime;
    float: right;
    width: 200px;
}
like image 74
SW4 Avatar answered Sep 22 '22 13:09

SW4