Consider the following code:
Option 1
Use float:left on both div elements and set a % width for both div elements with a combined total width of 100%.
Use box-sizing: border-box; on the floating div elements. The value border-box forces the padding and borders into the width and height instead of expanding it.
Use clearfix on the http://jsfiddle.net/dqC8t/3381/ Option 2 Use Add position:relative to http://jsfiddle.net/dqC8t/3382/ Option 3 Use And again (same as NOTE: inline-block elements can have spacing issues as it is affected by spaces in HTML markup. More information here: https://css-tricks.com/fighting-the-space-between-inline-block-elements/ http://jsfiddle.net/dqC8t/3383/ A final option would be to use the new display option named flex, but note that browser compatibility might come in to play: http://caniuse.com/#feat=flexbox http://www.sketchingwithcss.com/samplechapter/cheatsheet.html.clearfix:after {
content: " ";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
#first, #second{
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
#wrapper {
width: 500px;
border: 1px solid black;
}
#first {
border: 1px solid red;
float:left;
width:50%;
}
#second {
border: 1px solid green;
float:left;
width:50%;
}
position:absolute on one element and a fixed width on the other element.#wrapper {
width: 500px;
border: 1px solid black;
position:relative;
}
#first {
border: 1px solid red;
width:100px;
}
#second {
border: 1px solid green;
position:absolute;
top:0;
left:100px;
right:0;
}
display:inline-block on both div elements and set a % width for both div elements with a combined total width of 100%.float:left example) use box-sizing: border-box; on the div elements. The value border-box forces the padding and borders into the width and height instead of expanding it.#first, #second{
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
#wrapper {
width: 500px;
border: 1px solid black;
position:relative;
}
#first {
width:50%;
border: 1px solid red;
display:inline-block;
}
#second {
width:50%;
border: 1px solid green;
display:inline-block;
}