.container {
display: flex;
border: 5px solid blue;
height: 200px;
flex-wrap:wrap;
width: fit-content;
.div-1 {
border: 5px solid red;
width: 230px;
}
.div-2 {
border: 5px solid green;
width: 200px;
}
.div-3 {
border: 5px solid green;
width: 200px;
}
.div-4 {
border: 5px solid green;
width: 200px;
}
.div-5 {
border: 5px solid green;
width: 200px;
}
.div-6 {
border: 5px solid green;
width: 200px;
}
.div-7 {
border: 5px solid green;
width: 400px;
}
.div-8 {
border: 5px solid green;
width: 400px;
}
}
<div class="container">
<div class="div-1">I'm 230 px wide</div>
<div class="div-2">I'm take up what is left in the view port!</div>
<div class="div-3"></div>
<div class="div-4"></div>
<div class="div-5"></div>
<div class="div-6"></div>
<div class="div-7"></div>
<div class="div-8"></div>
</div>
I want to set the width of flex-container to be equal to the width of flex-items, so that there is no remaining empty space at the end..
Attached Code for reference. Here I would like to fix width of the container to be equal to width of first 6 divs combined.
.container {
display: inline-flex;
border: 5px solid blue;
height: 200px;
width: fit-content;
flex-wrap: wrap;
.div-1 {
border: 5px solid red;
width: 230px;
}
.div-2 {
border: 5px solid green;
width: 200px;
}
.div-3 {
border: 5px solid green;
width: 200px;
}
.div-4 {
border: 5px solid green;
width: 200px;
}
.div-5 {
border: 5px solid green;
width: 200px;
}
.div-6 {
border: 5px solid green;
width: 200px;
}
.div-7 {
border: 5px solid green;
width: 400px;
}
.div-8 {
border: 5px solid green;
width: 300px;
}
}
.next-line {
height: 100px;
border: 5px solid orange;
}
<div class="container">
<div class="div-1">I'm 230 px wide</div>
<div class="div-2">I'm take up what is left in the view port!</div>
<div class="div-3"></div>
<div class="div-4"></div>
<div class="div-5"></div>
<div class="div-6"></div>
<div class="div-7"></div>
<div class="div-8"></div>
</div>
<div class="next-line">
I'm the next div element!
</div>