IE11 flex issues with wrapping content - css

I have the following code which has four columns wrapped over 2 rows using flex. In chrome and firefox, this works perfectly with the first item taking it's own row and then the second row, all the items match the tallest in that row.
However in IE11, the items in the second row match the tallest item out of all 4 (rather than just on it's own row) meaning that there is a lot of white space created in the second row.
* {
box-sizing: border-box;
}
img {
display: block;
width: 100%;
}
.grid-container {
padding-left: 0;
padding-right: 0;
margin-right: 0;
margin-left: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
flex: 0 1 auto;
}
.grid-column {
padding-right: 12px;
padding-bottom: 24px;
padding-left: 12px;
flex-basis: 100%;
flex: 0 0 auto;
max-width: 100%;
margin-left: 0;
margin-right: 0;
flex-direction: column;
display: flex;
}
.grid-column:nth-child(1) {
min-width: 100%;
max-width: 100%;
}
.grid-column:nth-child(2) {
min-width: 50%;
max-width: 50%;
}
.grid-column:nth-child(3),
.grid-column:nth-child(4) {
min-width: 25%;
max-width: 25%;
}
.grid-column:nth-child(1) {
min-width: 100%;
max-width: 100%;
}
.widget-article {
display: flex;
flex-direction: column;
flex-grow: 1;
}
.grid-column:nth-child(1) .widget-article {
flex-direction: row;
}
.widget-article__content {
background: #313B3D;
color: #ffffff;
flex-grow: 1;
}
.widget-article__content a {
color: #ffffff;
}
<div class="grid-container grid-container--listing grid-container--full-half-quarter">
<div class="grid-column">
<div class="widget-article widget-article--full widget-article--featured widget-article--theme-3">
<div class="media-asset">
<a href="#">
<img src="http://via.placeholder.com/986x553" alt="">
</a>
</div>
<div class="widget-article__content">
<div class="widget-article__header">
<h3 class="widget-article__title">
<a class="widget-article__title-link" href="#">
Crash-tested landscape furniture: why functional will no longer do...
</a>
</h3>
</div>
<div class="widget-article__footer">
<div class="widget-article__meta">
<div class="widget-article__meta-left">
<div class="meta-details">
<div class="meta-details__author">
<p><a class="meta-details__author-link" href="#">CHRISTOPHER HAINES</a></p>
</div>
<div class="meta-details__date">
<p>MONDAY 5TH JUNE, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="grid-column">
<div class="widget-article widget-article--full widget-article--featured widget-article--theme-3">
<div class="media-asset">
<a href="#">
<img src="http://via.placeholder.com/986x553" alt="">
</a>
</div>
<div class="widget-article__content">
<div class="widget-article__header">
<h3 class="widget-article__title">
<a class="widget-article__title-link" href="#">
Crash-tested landscape furniture: why functional will no longer do...
</a>
</h3>
</div>
<div class="widget-article__footer">
<div class="widget-article__meta">
<div class="widget-article__meta-left">
<div class="meta-details">
<div class="meta-details__author">
<p><a class="meta-details__author-link" href="#">CHRISTOPHER HAINES</a></p>
</div>
<div class="meta-details__date">
<p>MONDAY 5TH JUNE, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="grid-column">
<div class="widget-article widget-article--full widget-article--featured widget-article--theme-3">
<div class="media-asset">
<a href="#">
<img src="http://via.placeholder.com/986x553" alt="">
</a>
</div>
<div class="widget-article__content">
<div class="widget-article__header">
<h3 class="widget-article__title">
<a class="widget-article__title-link" href="#">
Crash-tested landscape furniture: why functional will no longer do...
</a>
</h3>
</div>
<div class="widget-article__footer">
<div class="widget-article__meta">
<div class="widget-article__meta-left">
<div class="meta-details">
<div class="meta-details__author">
<p><a class="meta-details__author-link" href="#">CHRISTOPHER HAINES</a></p>
</div>
<div class="meta-details__date">
<p>MONDAY 5TH JUNE, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="grid-column">
<div class="widget-article widget-article--full widget-article--featured widget-article--theme-3">
<div class="media-asset">
<a href="#">
<img src="http://via.placeholder.com/986x553" alt="">
</a>
</div>
<div class="widget-article__content">
<div class="widget-article__header">
<h3 class="widget-article__title">
<a class="widget-article__title-link" href="#">
Crash-tested landscape furniture: why functional will no longer do...
</a>
</h3>
</div>
<div class="widget-article__footer">
<div class="widget-article__meta">
<div class="widget-article__meta-left">
<div class="meta-details">
<div class="meta-details__author">
<p><a class="meta-details__author-link" href="#">CHRISTOPHER HAINES</a></p>
</div>
<div class="meta-details__date">
<p>MONDAY 5TH JUNE, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / column -->
</div>
Is there a way to make IE behave like chrome and firefox without changing the html structure?

You can replace flexbox for most elements except .container using display: table. Result:
* {
box-sizing: border-box;
}
img {
display: block;
width: 100%;
}
.grid-container {
padding-left: 0;
padding-right: 0;
margin-right: 0;
margin-left: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
flex: 0 1 auto;
}
.grid-column {
padding-right: 12px;
padding-bottom: 24px;
padding-left: 12px;
max-width: 100%;
margin-left: 0;
margin-right: 0;
}
.grid-column:nth-child(1) {
min-width: 100%;
max-width: 100%;
}
.grid-column:nth-child(2) {
min-width: 50%;
max-width: 50%;
}
.grid-column:nth-child(3),
.grid-column:nth-child(4) {
min-width: 25%;
max-width: 25%;
}
.grid-column:nth-child(1) {
min-width: 100%;
max-width: 100%;
}
.widget-article {
display: table;
height: 100%;
}
.widget-article > * {
display: table-row;
}
.grid-column:first-child .widget-article > * {
display: table-cell;
vertical-align: top;
}
.widget-article__content {
background: #313B3D;
color: #ffffff;
height: 100%;
}
.widget-article__content a {
color: #ffffff;
}
<div class="grid-container grid-container--listing grid-container--full-half-quarter">
<div class="grid-column">
<div class="widget-article widget-article--full widget-article--featured widget-article--theme-3">
<div class="media-asset">
<a href="#">
<img src="http://via.placeholder.com/986x553" alt="">
</a>
</div>
<div class="widget-article__content">
<div class="widget-article__header">
<h3 class="widget-article__title">
<a class="widget-article__title-link" href="#">
Crash-tested landscape furniture: why functional will no longer do...
</a>
</h3>
</div>
<div class="widget-article__footer">
<div class="widget-article__meta">
<div class="widget-article__meta-left">
<div class="meta-details">
<div class="meta-details__author">
<p><a class="meta-details__author-link" href="#">CHRISTOPHER HAINES</a></p>
</div>
<div class="meta-details__date">
<p>MONDAY 5TH JUNE, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="grid-column">
<div class="widget-article widget-article--full widget-article--featured widget-article--theme-3">
<div class="media-asset">
<a href="#">
<img src="http://via.placeholder.com/986x553" alt="">
</a>
</div>
<div class="widget-article__content">
<div class="widget-article__header">
<h3 class="widget-article__title">
<a class="widget-article__title-link" href="#">
Crash-tested landscape furniture: why functional will no longer do...
</a>
</h3>
</div>
<div class="widget-article__footer">
<div class="widget-article__meta">
<div class="widget-article__meta-left">
<div class="meta-details">
<div class="meta-details__author">
<p><a class="meta-details__author-link" href="#">CHRISTOPHER HAINES</a></p>
</div>
<div class="meta-details__date">
<p>MONDAY 5TH JUNE, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="grid-column">
<div class="widget-article widget-article--full widget-article--featured widget-article--theme-3">
<div class="media-asset">
<a href="#">
<img src="http://via.placeholder.com/986x553" alt="">
</a>
</div>
<div class="widget-article__content">
<div class="widget-article__header">
<h3 class="widget-article__title">
<a class="widget-article__title-link" href="#">
Crash-tested landscape furniture: why functional will no longer do...
</a>
</h3>
</div>
<div class="widget-article__footer">
<div class="widget-article__meta">
<div class="widget-article__meta-left">
<div class="meta-details">
<div class="meta-details__author">
<p><a class="meta-details__author-link" href="#">CHRISTOPHER HAINES</a></p>
</div>
<div class="meta-details__date">
<p>MONDAY 5TH JUNE, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="grid-column">
<div class="widget-article widget-article--full widget-article--featured widget-article--theme-3">
<div class="media-asset">
<a href="#">
<img src="http://via.placeholder.com/986x553" alt="">
</a>
</div>
<div class="widget-article__content">
<div class="widget-article__header">
<h3 class="widget-article__title">
<a class="widget-article__title-link" href="#">
Crash-tested landscape furniture: why functional will no longer do...
</a>
</h3>
</div>
<div class="widget-article__footer">
<div class="widget-article__meta">
<div class="widget-article__meta-left">
<div class="meta-details">
<div class="meta-details__author">
<p><a class="meta-details__author-link" href="#">CHRISTOPHER HAINES</a></p>
</div>
<div class="meta-details__date">
<p>MONDAY 5TH JUNE, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / column -->
</div>

The problem in IE11 is that it uses the intrinsic height of the image.
Although you've set the width of the image containers:
.grid-column:nth-child(1) {
min-width: 100%;
max-width: 100%;
}
.grid-column:nth-child(2) {
min-width: 50%;
max-width: 50%;
}
.grid-column:nth-child(3),
.grid-column:nth-child(4) {
min-width: 25%;
max-width: 25%;
}
... which is enough to get the layout to work in Chrome and Firefox, these rules are not enough to alter the image's natural dimensions in IE11.
So consider adding something like this to your code:
/* pixel units for illustration purposes only */
.grid-column:nth-child(2) img {
height: 250px;
}
.grid-column:nth-child(3) img,
.grid-column:nth-child(4) img {
height: 125px;
}
jsFiddle demo
Percentage heights are probably preferable to pixels, but that will take some work setting heights on ancestors. Since I don't know exactly what you want, I just used pixels for the demo. There may also be other sizing options you can use.
But the bottom line is, you need to override the intrinsic dimensions of the image for the layout to work in IE11.

Related

CSS vertically space even divs in IE 11

I was creating a layout which worked in the latest updated browsers (Firefox, Chrome, ...) and then opened the layout in IE 11 and saw a difference. My layout in IE looks like this:
But in every other tested browser the space on the right sided divs is evenly between them, which means that the third div stays on the bottom, while the second divs is right in the middle. I can't get it working in IE 11 and hoped that someone from here has a good advice.
https://jsfiddle.net/1gq2cj3f/2/
<article class="col-12 content-wrapper">
<div class="row content-wrapper-materials">
<div class="col-12 col-lg-6 materials-sectors">
<div class="card materials-sectors-general">
<div class="row no-gutters">
<div class="col-12">
<header class="card-header">
<div class="card-image">
<a href="...">
<img class="card-img-top" src="..." alt="" width="568px" height="430px">
</a>
</div>
<div class="card-img-overlay">
<h3 class="card-title">
Allgemein </h3>
</div>
</header>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-6 materials-sectors">
<div class="materials-sectors-specific">
<div class="card specific-construction">
<div class="row no-gutters">
<div class="col-12 col-sm-4">
<header class="card-header">
<div class="card-image">
<a href="...">
<img class="card-img-top" src="..." alt="" width="190px" height="117px">
</a>
<div class="card-img-overlay">
<h3 class="card-title">
Headline </h3>
</div>
</div>
</header>
</div>
<div class="col-12 col-sm-8">
<div class="card-body" itemprop="description">
<p class="card-text">
Text </p>
</div>
</div>
</div>
</div>
<div class="card specific-healthcare">
<div class="row no-gutters">
<div class="col-12 col-sm-4">
<header class="card-header">
<div class="card-image">
<a href="...">
<img class="card-img-top" src="..." alt="" width="190px" height="117px">
</a>
<div class="card-img-overlay">
<h3 class="card-title">
Headline </h3>
</div>
</div>
</header>
</div>
<div class="col-12 col-sm-8">
<div class="card-body" itemprop="description">
<p class="card-text">
Text </p>
</div>
</div>
</div>
</div>
<div class="card specific-ict">
<div class="row no-gutters">
<div class="col-12 col-sm-4">
<header class="card-header">
<div class="card-image">
<a href="...">
<img class="card-img-top" src="..." alt="" width="190px" height="117px">
</a>
<div class="card-img-overlay">
<h3 class="card-title">
Headline </h3>
</div>
</div>
</header>
</div>
<div class="col-12 col-sm-8">
<div class="card-body" itemprop="description">
<p class="card-text">
Text </p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</article>
.content-wrapper > div {
max-width: 1200px;
margin-right: auto;
margin-left: auto;
padding-top: 8rem;
padding-bottom: 8rem;
}
.card > * {
flex: 0 0 auto;
}
.materials-sectors .card-header {
height: 100%;
padding: 0;
border-bottom: 0;
background-color: rgba(242, 241, 241, 1) !important;
}
.materials-sectors .card-image {
height: 100%;
}
.materials-sectors .card-img-top {
-o-object-fit: cover;
object-fit: cover;
}
.materials-sectors-general .card-img-overlay {
bottom: 2rem;
padding: 0.75rem;
}
.materials-sectors .card-img-overlay {
background-color: rgba(255, 255, 255, 0.25);
top: auto;
}
.card-img-overlay > h3 {
font-size: 1rem;
margin-bottom: 0;
}
.materials-sectors-specific {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-flow: column;
flex-flow: column;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.materials-sectors-specific > .card {
height: 100%;
}
.materials-sectors-specific .card-image {
display: block;
}
.materials-sectors-specific > div:nth-of-type(2) {
margin-top: 1rem;
margin-bottom: 1rem;
}

CSS how to align different size images with text inside row?

Need to align four different height (beetween 160-180px) svg images with text under them.
Images should be placed in line at sight and I don't know how to make strict align short text under them in one line like on screenshot.
Thanks!
UPD: Sorry for inconvinient information, thought that this question is quite typical for those who know css good.
Here is my html and css. Also I'm using bootstrap rows.
<div class="did-you-know">
<div class="row items">
<div class="col-lg-3 col-xs-6">
<div class="icon">
<img src="/img/mswa/inline-wa.svg"/>
</div>
<div class="title text-poppins">
<p>We’re from WA</p>
<p>{like you!}</p>
</div>
</div>
<div class="col-lg-3 col-xs-6">
<div class="icon">
<img src="/img/mswa/inline-packaging.svg"/>
</div>
<div class="title text-poppins">
<p>We use minimal packaging</p>
<p>{great for the planet}</p></div>
</div>
<div class="col-lg-3 col-xs-6">
<div class="icon">
<img src="/img/mswa/inline-quality.svg"/>
</div>
<div class="title text-poppins">
<p>We only choose quality</p>
<p>{better for your health}</p></div>
</div>
<div class="col-lg-3 col-xs-6">
<div class="icon">
<img src="/img/mswa/inline-community.svg"/>
</div>
<div class="title text-poppins">
<p>We love giving back</p>
<p>{great for our community}</p></div>
</div>
</div>
</div>
.did-you-know {
padding: 20px;
text-align: center;
}
.did-you-know .items .icon {
padding: 50px;
}
.did-you-know .items .title {
font-size: 20px;
}
here is a solution:
Replace images by your images.
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
.column {
float: left;
width: 25%;
padding: 5px;
}
/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
}
</style>
</head>
<body>
<div class="row">
<div class="column">
<img src="https://freesvg.org/img/cartoonsun.png" alt="Snow" style="width:100%">
<p style='text-align: center;'>test1</p>
</div>
<div class="column">
<img src="https://freesvg.org/img/cartoonsun.png" alt="Forest" style="width:100%">
<p style='text-align: center;'>test2</p>
</div>
<div class="column">
<img src="https://freesvg.org/img/cartoonsun.png" alt="Mountains" style="width:100%">
<p style='text-align: center;'>test3</p>
</div>
<div class="column">
<img src="https://freesvg.org/img/cartoonsun.png" alt="Mountains" style="width:100%">
<p style='text-align: center;'>test3</p>
</div>
</div>
</body>
</html>

How to make the header take up the full width in a media query?

I wrote the media queries for smaller screens ,but i can not seem to make them work for ipads. I have a problem with the width of the header and the navbar. They don't seem to take up the full width even though I wrote margin and padding 0 (as an asterisk). The max-width of the html is 1600px. Here is a Print screen.
<header>
<div class="Header-TopContainer">
<div class="Header-MyAccountItem">
<i class="fas fa-user account "></i>
</div>
<div class="Header-MyAccount">
My Account
</div>
<div class="Header-CartItem">
<i class="fas fa-cart-plus cart"></i>
</div>
<div class="Header-Cart">
Cart
</div>
<div class="Header_CheckoutItem">
<i class="fas fa-check-circle check"></i>
</div>
<div class="Header-Checkout">
Checkout
</div>
<div class="Header-VerticalLine"><img src="./Images/first%20hr.png" alt="vertical line"></div>
<div class="Header-Search"><i class="fas fa-search" id="search"></i></div>
</div>
<div class="line mqtablet">
<img src="./Images/long.png" alt="vertical line">
</div>
<div class="Header-LogoContainer mqtablet">
<div class="Header-LogoText">
<h1>Car<span style="color:#ff3448">Store</span></h1>
<p class="Header-LogoSubText">Best Car Seller</p>
</div>
<div class="Header-Phone">
<div class="Header-PhoneIcon">
<i class="fas fa-mobile-alt mobile"></i>
<h2>+123 456 7890</h2>
</div>
<div class="Header-PhoneNumber">
<p class="Header-WorkingHours">mon-fri:8:30am-7:30pm; sat-sun:9:30am-4:30pm</p>
</div>
</div>
<div class="Header-container">
<div class="Header-Wishlist">
<div class="Header-WishlistVLine vline">
<img src="./Images/first%20hr.png" alt="vertical line">
</div>
<div class="Wishlist">
<div class="Header-WishlistIcon">
<i class="fas fa-star wishlisticon"></i>
</div>
<div class="Header-WishlistText">
Wishlist
</div>
</div>
</div>
<div class="Header-Compare">
<div class="Header-WishlistVLine">
<img src="./Images/first%20hr.png" alt="vertical line">
</div>
<div class="Compare">
<div class="Header-CompareIcon">
<i class="fas fa-car compareicon"></i>
</div>
<div class="Header-CompareText">
Compare
</div>
</div>
</div>
<div class="Header-MyCart">
<div class="Header-WishlistVLine">
<img src="./Images/first%20hr.png" alt="vertical line">
</div>
<div class="Mycart">
<div class="Header-MyCartIcon">
<i class="fas fa-cart-plus cart mycarticon"></i>
</div>
<div class="Header-MyCartText'">
My cart
</div>
</div>
</div>
</div>
</div>
</header>
<nav class="toggle-menu">
<label for="toggle">☰</label>
<input type="checkbox" id="toggle"/>
<ul class="MainMenu">
<li>Home</li>
<li>Services</li>
<li>About</li>
<li>Reviews</li>
<li>Locations</li>
<li>Contacts</li>
</ul>
</nav>
#media(min-width:768px) and (max-width:1024px) {
header {
position: relative;
height: 17rem;
text-align: center;
}
.Header-TopContainer,
.Header-Phone {
display: none;
}
.mqtablet {
display: flex;
flex-direction: column;
text-align: center;
}
.Header-LogoText {
margin: 0.5rem;
}
.line {
position: absolute;
top: 9rem;
}
.Header-container {
margin-left: 10%;
}
.vline {
display: none;
}
nav {
text-align: center;
}
ul {
flex-wrap: nowrap;
justify-content: flex-end;
padding-right: 9rem;
}
ul li a {
padding-left: 5rem;
}

Flexbox padding between items but not edges

I have a basic flexbox implementation like this
.holder {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
max-width: 500px;
background: wheat;
}
.col img {
max-width: 100%;
}
.col {
width: 20%;
float: left;
text-align: center;
}
<div class="holder">
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
</div>
I am trying to add some padding in between each of the items but not at the edges.
Is flexbox the best solution for this and does anybody have an example they can point me at?
You can use the flex-basis property where you set the initial width using the calc() function:
.holder {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
max-width: 500px;
background: wheat;
}
.col img {
max-width: 100%;
}
.col {
/*width: 20%;*/
/*float: left; not necessary*/
flex-basis: calc(20% - 5px);
text-align: center;
}
/* addition, if desired */
img {
display: block; /* removes bottom margin/whitespace; "vertical-align: bottom" does the same */
}
<div class="holder">
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div class="col">
<img src="https://dummyimage.com/600x400/000/fff">
</div>
</div>
For flex box it is pretty easy. Just make the correct width for the items and set justify-content property of container to space-between. Make sure the sum of widths of items is less than 100% width of container.

Getting alternative columns to have text on top in css

I'm trying to create a page where I have image 1 on top and the text at the bottom and image 2 at the bottom and the text on top. I'm not sure how to go about doing it this way.
In my JSFIDDLE I would like "Text 1" to be at the bottom. "Text 2" on top and "Text 3" at the bottom.
my html
<div class="gallery_wrapper">
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/QuLaaLb.jpg">
</div>
<div class="gallery_title">
<h2>
Text 1
</h2>
</div>
</div>
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/vFEg6ef.jpg">
</div>
<div class="gallery_title">
<h2>
Text 2
</h2>
</div>
</div>
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/QuLaaLb.jpg">
</div>
<div class="gallery_title">
<h2>
Text 3
</h2>
</div>
</div>
JSFIDDLE
This should help you get started. You can use flex and pseudo-properties to achieve this.
.gallery_wrapper {
display: flex;
}
.gallery {
background: #333333;
}
.gallery:nth-child(even) {
display: flex;
flex-direction: column-reverse;
}
.gallery_title {
color: #fff
}
<div class="gallery_wrapper">
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/vFEg6ef.jpg">
</div>
<div class="gallery_title">
<h2>
Text 1
</h2>
</div>
</div>
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/vFEg6ef.jpg">
</div>
<div class="gallery_title">
<h2>
Text 2
</h2>
</div>
</div>
<div class="gallery">
<div class="gallery_image">
<img src="http://i.imgur.com/vFEg6ef.jpg">
</div>
<div class="gallery_title">
<h2>
Text 3
</h2>
</div>
</div>
</div>
You can use flexbox for your requirement.
In flexbox there are two properties with which you can solve your issue. Either using order or using flex-direction. But flex-direction is for parent and order is for child. So you can use any of the properties to solve your problem.
In this example snippet, I use order.
.item {
display: flex;
flex-direction: column;
}
.text {
font-size: 20px;
}
.image {
display: flex;
width: 200px;
height: 200px;
background-image: url('https://files.allaboutbirds.net/wp-content/themes/html5blank-stable/images/blue-winged-warbler.jpg');
background-size: cover;
background-repeat: no-repeat;
}
.item:nth-child(2n) .text {
order: 2;
}
<section>
<div class="item">
<span class="text">Text 1</span>
<span class="image"></span>
</div>
<div class="item">
<span class="text">Text 2</span>
<span class="image"></span>
</div>
<div class="item">
<span class="text">Text 3</span>
<span class="image"></span>
</div>
</section>
You can add the following CSS to achieve this.
.gallery{
position: relative;
}
.gallery_title{
position: absolute;
bottom: 5px;
left: 0;
}
.gallery:nth-child(even) .gallery_title{
bottom: auto;
top: 5px;
}
Check the link here jsfiddle

Resources