Reputation: 3308
I have created a simple HTML page, where I have a parent div
with over-flow enabled in both axes. Now within that div
, there are 2 div
s which I want to place side by side.
#Result {
margin: 0 auto;
padding: 0;
background-color: rgba(0, 0, 0, .02);
padding-top: 25px;
font-size: 16px;
overflow: scroll;
width: 99%;
height: calc(100% - 90px - 70px);
position: absolute;
}
#Left,
#Right {
height: calc(99vh - 90px - 70px);
width: 28vw;
margin: 0 auto;
padding: 0;
display: inline-block;
float: left;
text-align: center;
background-color: rgba(0, 0, 0, .04);
border-right: 1px solid #a6a6a6;
border-bottom: 1px solid #a6a6a6;
}
#Right {
background-color: rgba(0, 0, 0, .5);
border-right: 0px solid #737373;
padding-left: 15px;
margin-right: 15px;
width: 2000px;
}
<div id='Result'>
<div id='Left'>
</div>
<div id='Right'>
</div>
</div>
Codepen - https://codepen.io/Volabos/pen/qBdNyPa?editors=1100
However unfortunately, the 3rd div
is moved down if its width is taken a large number. How can I place the 2nd and 3rd div
side by side?
Upvotes: 1
Views: 552
Reputation: 144
Floats can be a way, but I'd rather go with flexbox:
#result {
display: flex;
justify-content: space-between // or flex-start, center, flex-end ... whatever
}
Your #Left and #Right will be placed side by side and will have the same height by default.
EDIT: Container with two children aligned next to each other, including a horizontal scrollbar:
<style>
.container{
display: flex;
justify-content: space-between;
overflow: scroll;
border: 1px solid blue;
}
.child {
width: 60%;
flex-shrink: 0;
height: 100px;
border: 1px solid red;
}
</style>
<div class="container">
<div class="child"></div>
<div class="child"></div>
</div>
Upvotes: 1
Reputation: 105853
You may safely use for the parent display:flex
+ overflow:auto
and for the children flex-shrink:0
or min-width:xx
Possible example
#Result {
display: flex; /* flex model */
overflow: auto;
height: 100vh; /* whatever or min-height or let grow from content */
}
#Right,
#Left {
flex-shrink: 0; /* do not allow childd to shrink and allow overflow */
}
#Left {
width: 28vw; /* whatever */
}
#Right {
width: 100vw; /* whatever */
}
/* demo purpose */
div div {
border: solid;
}
#Left {
background: lightblue;
}
#Right {
background: lightgreen;
}
* {
margin: 0;
box-sizing: border-box;
}
<div id='Result'>
<div id='Left'>
</div>
<div id='Right'>
</div>
</div>
Upvotes: 1
Reputation: 32
Try this, if you don't mind bodging it a little bit:
#left {
width: 150px;
float: left;
padding-left: 50px;
}
#right {
/* Change this to whatever the width of your left column is*/
margin-left: 215px;
text-align: left;
font-size: 18px;
}
.clear {
clear: both;
}
<div id="left">
<p>foo</p>
</div>
<div id="right">
<p>bar</p>
</div>
<div id="clear"></div>
Upvotes: 0
Reputation: 39
.flex-container {
display: flex;
align-items: stretch;
background-color: #f1f1f1;
}
.flex-container>div {
background-color: DodgerBlue;
color: white;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
<div class="flex-container">
<div style="flex-grow: 1">1</div>
<div style="flex-grow: 1">2</div>
<div style="flex-grow: 8">3</div>
</div>
Upvotes: 0
Reputation: 1468
You can use float:left;
and clear:right;
https://codepen.io/osmanraifgunes/pen/PoqzByB?editors=1100
Upvotes: 0