I am trying to create a flexbox with 6 boxes that go across the page.
However, for some reason it won't behave properly as they have different sizes.
they must behave like this:
/* =================================
Base Styles
==================================== */
body {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.row {
flex: 1;
}
/* =================================
Media Queries
==================================== */
@media (min-width: 769px) {
.main-header,
.main-nav,
.row {
display: flex;
}
.main-header {
flex-direction: column;
align-items: center;
}
.col {
flex: 1 50%;
}
.row {
flex-wrap: wrap;
}
.item-2 {
order: -1;
}
}
@media (min-width: 1025px) {
.main-header {
flex-direction: row;
justify-content: space-between;
}
.col {
flex-basis: 0;
}
.item-1 {
flex-grow: 1.4;
}
}
<div class="row">
<div class="item-1 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.primary-->
<div class="item-2 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.secondary-->
<div class="item-3 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.tertiary-->
<div class="item-4 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.tertiary-->
<div class="item-5 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.tertiary-->
<div class="item-6 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.tertiary-->
</div>
YOU CAN VIEW THE JSFIDDLE HERE: https://jsfiddle.net/ju157mnj/2/
Images can be aligned using both the text-align and flexbox properties. Applying text-align to an image's parent element can be used to right, left or center align the image. You can also use right and left float to position an image along the desired container's edge.
Justify Content Flex Start positions element at the start of the page. Flex End sets the element to the end of the page. Space Around arranges the items evenly but with spaces between them. The spaces will be equal among all the elements inside a flex-box container, but not outside them.
.row {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.col {
flex: 0 0 calc(33.33% - 30px); /* flex-basis adjustment for margin */
margin: 5px;
}
img {
width: 100%;
}
<div class="row">
<div class="item-1 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.primary-->
<div class="item-2 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.secondary-->
<div class="item-3 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.tertiary-->
<div class="item-4 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.tertiary-->
<div class="item-5 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.tertiary-->
<div class="item-6 col">
<img src="http://blackrockdigital.github.io/startbootstrap-freelancer/img/portfolio/cabin.png">
</div><!--/.tertiary-->
</div>
Revised Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With