How To Put Multiple Divs Side By Side And Not Go To The Next Line
Fiddle: https://jsfiddle.net/29xxju45/ CSS: * { padding: 0; margin: 0; } body { padding: 2%; background: #0000CC; color: #FFF !important; } .minhold { z-index: 10
Solution 1:
Create a container class and use the calc
attribute on width...for example:
CSS:
.container {
width: calc(100% / 4);
height: 150px;
padding: 0;
margin: 0;
float: left;
}
HTML:
<divclass="minhold"><divclass="container"style="background: red;"></div><divclass="container"style="background: blue;"></div><divclass="container"style="background: green;"></div><divclass="container"style="background: pink;"></div></div>
In a nutshell, each container calculates it's parent width and gets divided by 4 (since you have 4 containers). If you want more containers, simply put 5 or more in place of 4.
Solution 2:
you have to define height and set overflow:auto;
Here is code: https://jsfiddle.net/29xxju45/2/
EDIT
for horizontal scrollbar
Solution 3:
I think you can use FlexModel.
.minhold {
display: flex;
flex-flow: row nowrap;
z-index: 10;
background-color: #ffffff;
padding: 0!important;
border-radius: 4px;
-moz-border-radius: 4px;
border: 1px solid #ddd;
margin-top: 6px;
margin-left: 0.4%;
-webkit-box-shadow: 06px12pxrgba(0,0,0,.175);
box-shadow: 06px12pxrgba(0,0,0,.175);
-moz-box-shadow: 06px12pxrgba(0,0,0,.175);
background-clip: padding-box;
opacity: 0.97;
filter: alpha(opacity=97);
width: 99%;
float: left;
}
.dmaxh {
overflow: hidden;
width: 31%;
float: left;
margin: 01%10px1%;
}
.main-content {
position: relative;
z-index: 10;
background: rgb(71, 194, 243);
padding: 5px5px10px5px;
border-radius: 15px;
border-top-left-radius: 0;
}
.box {
width: 50%;
height: 150px;
background: #990000;
overflow: hidden;
}
<divstyle="overflow: hidden; width: 100%; margin: -1.6rem 0 0 0;"><divclass="main-content"><divclass="maxh"style="overflow: hidden !important;"><divclass="minhold"><divclass="box"style="background: #009900;">
BOX 1
</div><divclass="box"style="background: #990000;">
BOX 2
</div><divclass="box"style="background: #000099;">
BOX 3
</div><divclass="box"style="background: #999;">
BOX 4
</div></div></div></div></div>
Solution 4:
In your HTML, you're hard coding the widths into each div, and the math doesn't check out. If you were to apply a block
class to each div and apply a width: 25%
you would fit four blocks side by side.
Updated Fiddled: https://jsfiddle.net/29xxju45/1/
Post a Comment for "How To Put Multiple Divs Side By Side And Not Go To The Next Line"