Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Positioning 70-30 with Inline-Block

Tags:

css

I am positioning main-bar and side-bar with 70-30 ratio as under: JSFIDDLE

.main-bar, .side-bar{
	position: relative;
	margin:0; padding: 0;
	outline: 0;
	display: inline-block;
	border:none;
    background:#CCC
}
.main-bar{width: 70%}
.side-bar{width: 30%}

/* This Works

.side-bar{width: 29%}

*/
<div class="main-bar">
    I am the King!
</div>

<div class="side-bar">
   I am not less!
</div>

Interestingly, it works with 70-29 ratio. Did I miss something?

like image 339
tika Avatar asked Nov 30 '25 07:11

tika


2 Answers

You have to remove white space between divs as it also take place and doesn't let inline-blocks align properly.

.main-bar, .side-bar {
    position: relative;
    margin: 0;
    padding: 0;
    outline: 0;
    display: inline-block;
    border: none;
    background: #CCC;
}
.main-bar {
    width: 70%;
}
.side-bar {
    width: 30%;
}
<div class="main-bar">
    I am the King!
</div><!--

--><div class="side-bar">
   I am not less!
</div>

Reference: Fighting the Space Between Inline Block Elements

like image 187
emmanuel Avatar answered Dec 01 '25 19:12

emmanuel


This is because the white space in-between your inline-block elements you need make them 0 using the font-size property just as follows

body{
    font-size: 0;
}
.main-bar, .side-bar{
    position: relative;
    margin:0; padding: 0;
    outline: 0;
    display: inline-block;
    font-size: 14px;
    border:none;
    background:#CCC
}
.main-bar{width: 70%}
.side-bar{width: 30%}

Working Fiddle

like image 35
Benjamin Avatar answered Dec 01 '25 21:12

Benjamin