Reputation: 23
I'm trying to place some divs inside one div, where last div has the overflow parameter used to make it somehow flexible to take the remaining space. jsfiddle to show en example.
HTML Code:
<div class="container">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<div class="box5"></div>
</div>
CSS code:
.container {
width: 400px;
height: auto;
border: 1px solid red;
margin: 0 auto;
}
.box1 {
width: 50px;
height: 100px;
border: 3px solid;
border-color: rgba(23, 23, 23, 0.5);
background-color: rgb(227, 227, 227);
margin: 4px 4px 4px 4px;
padding: 0px;
float: left;
}
.box2 {
width: 100px;
height: 50px;
border: 3px solid;
border-color: rgba(23, 23, 23, 0.5);
background-color: rgb(191, 239, 255);
margin: 4px 4px 4px 4px;
padding: 0px;
float: left;
}
.box3 {
width: 70px;
height: 30px;
border: 3px solid;
border-color: rgba(23, 23, 23, 0.5);
background-color: rgb(238, 212, 232);
margin: 4px 4px 4px 4px;
padding: 0px;
float: left;
}
.box4 {
width: 30px;
height: 100px;
border: 3px solid;
border-color: rgba(23, 23, 23, 0.5);
background-color: rgb(235, 252 ,212);
margin: 4px 4px 4px 4px;
padding: 0px;
float: left;
}
.box5 {
height: 70px;
border: 3px solid;
border-color: rgba(23, 23, 23, 0.5);
background-color: rgb(255, 173, 187);
margin: 4px 4px 4px 4px;
padding: 0px;
overflow: hidden;
}
Now I have two questions:
Upvotes: 0
Views: 70
Reputation: 115299
Actually, depending on what level of browser support you need, this is simple using flexbox
and you don't have to clear any floats...because their aren't any.
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
width: 80%;
height: auto;
border: 1px solid red;
margin: 1em auto;
overflow: auto;
display: flex;
}
.narrow {
width: 60%;
}
[class*="box"] {
margin: 4px;
padding: 0;
border: 3px solid;
}
.box1 {
width: 50px;
height: 100px;
border-color: rgba(23, 23, 23, 0.5);
background-color: rgb(227, 227, 227);
}
.box2 {
width: 100px;
height: 50px;
border-color: rgba(23, 23, 23, 0.5);
background-color: rgb(191, 239, 255);
}
.box3 {
width: 70px;
height: 30px;
border-color: rgba(23, 23, 23, 0.5);
background-color: rgb(238, 212, 232);
}
.box4 {
width: 30px;
height: 100px;
border-color: rgba(23, 23, 23, 0.5);
background-color: rgb(235, 252, 212);
}
.box5 {
height: 70px;
border-color: rgba(23, 23, 23, 0.5);
background-color: rgb(255, 173, 187);
flex: 1;
}
<div class="container">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<div class="box5"></div>
</div>
<div class="container narrow">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<div class="box5"></div>
</div>
Upvotes: 0
Reputation: 363
add this to your styleshit:
.container div{
margin-right:4px;
margin-left:0 !important;
}
.container div:nth-of-type(1){
margin-left:4px !important;
}
Upvotes: 0
Reputation: 363
add to .container overflow:hidden
.container {
width: 400px;
height: auto;
border: 1px solid red;
margin: 0 auto;
overflow:hidden
}
Upvotes: 1