Reputation: 429
I have a outer div having two inner divs in that one div(leftDiv) has a left-border of 1px this cause the right div to be moved out of the outerDiv.
CSS
.outerDiv{
display: block;
background: none repeat scroll 0% 0% #FFF;
height: 400px;
margin: 1%;
width: 97.5%;
border: 1px solid #D6D6D6;
box-shadow: 1px 0px 13px -2px #D6D6D6;
border-radius: 6px;
}
.leftDiv{
height: 400px;
width: 65%;
float: left;
border-right: 1px solid #D6D6D6;
}
.rightDiv{
height: 400px;
width: 35%;
float: left;
background:orange;
}
JSfiddle:LINK
I need the rightDiv to occupy the complete remaining space of outerDiv
Upvotes: 1
Views: 101
Reputation: 487
See changes, make display:inline
of the divs
and float
correctly.
All browsers friendly
Upvotes: 0
Reputation: 41842
Add margin-left: -1px
to .rightDiv
.
.rightDiv{
height: 400px;
width: 35%;
float: left;
background:orange;
margin-left:-1px;
}
I added -1px
margin to .rightDiv
to cutoff the border-right space of the .leftDiv
. which is 1px
.
OR
Using positioning
- Fiddle
OR
Using display: table-cell
- Fiddle
Upvotes: 1
Reputation: 15609
So many different answers here, all of which are good. I'm just posting this one just as another alternative, but maybe not necessarily the best option.
I added an :after
, so no actual code was changed in the way it looked.
This way, you don't need to make anything bigger, or smaller. Just add something on top of the current .leftDiv
.
Add
position:relative;
to .leftDiv
's css.
Then add this to the CSS:
.leftDiv:after{
content:'';
position:absolute;
top:0;
bottom:0;
right:0;
width:1px;
background:#333;
z-index:9999;
}
Upvotes: 0
Reputation: 15807
use box-sizing: border-box
.leftDiv{
height: 400px;
width: 65%;
float: left;
border-right: 1px solid #D6D6D6;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
Upvotes: 0
Reputation: 4492
Because 65% + 35% + 1px
is higher than 100%
, it shifts down.
Lower one of the percents by one and you have it working!
Upvotes: 0
Reputation: 123397
Add this rule
.outerDiv div {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
Example fiddle: http://jsfiddle.net/267SR/2/
box-sizing: border-box;
will include the border size inside the width of the div elements
Upvotes: 0
Reputation: 1439
you can use css3's calc property to deal with percentage and pixels both at a time.. use:
.leftDiv{
height: 400px;
width: calc(65% - 1px);
float: left;
border-right: 1px solid #D6D6D6;
}
check this: http://jsfiddle.net/267SR/1/
Upvotes: 0
Reputation: 421
Here are two solutions:
Upvotes: 1