I'm trying to get the image to appear on the left with content on the right.
desired output would be:
my images on the below appear above the content. I've tried a number of things with the flex-direction but just can't get the image to appear on the left.
here's my cut down code, any suggestions would be greatly appreciated.
<style>html {
background: #f5f7f8;
font-family: 'Roboto', sans-serif;
-webkit-font-smoothing: antialiased;
padding: 20px 0;
}
.band {
width: 90%;
max-width: 1240px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: auto;
grid-gap: 20px;
}
#media only screen and (min-width: 500px) {
.band {
grid-template-columns: 1fr 1fr;
}
.item-1 {
grid-column: 1/ span 2;
}
.item-1 h1 {
font-size: 30px;
}
}
#media only screen and (min-width: 850px) {
.band {
grid-template-columns: 1fr 1fr 1fr 1fr;
}
}
/* card */
.card {
min-height: 100%;
background: white;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
text-decoration: none;
color: #444;
position: relative;
top: 0;
transition: all .1s ease-in;
}
.card:hover {
top: -2px;
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.2);
}
.card article {
padding: 20px;
display: flex;
flex: 1;
justify-content: space-between;
flex-direction: column;
}
.card .thumb {
padding-bottom: 60%;
background-size: cover;
background-position: center center;
}
.card p {
flex: 1;
/* make p grow to fill available space*/
line-height: 1.4;
}
/* typography */
h1 {
font-size: 20px;
margin: 0;
color: #333;
}
.card span {
font-size: 12px;
font-weight: bold;
color: #999;
text-transform: uppercase;
letter-spacing: .05em;
margin: 2em 0 0 0;
}
</style>
<div class="support-grid"></div>
<div class="band">
<div class="item-4">
<a href="#" class="card">
<div class="thumb" style="background-image: url(https://thumbs.dreamstime.com/z/positive-pension-happiness-money-saving-retirement-financia-positive-pension-happiness-money-saving-retirement-financial-118207382.jpg);"></div>
<article>
<h1>title</h1>
<p></p>
<span>content</span>
</article>
</a>
</div>
<div class="item-5">
<a href="#" class="card">
<div class="thumb" style="background-image: url(https://thumbs.dreamstime.com/z/positive-pension-happiness-money-saving-retirement-financia-positive-pension-happiness-money-saving-retirement-financial-118207382.jpg);"></div>
<article>
<h1>title</h1>
<p></p>
<span>content</span>
</article>
</a>
</div>
<div class="item-6">
<a href="#" class="card">
<div class="thumb" style="background-image: url(https://thumbs.dreamstime.com/z/positive-pension-happiness-money-saving-retirement-financia-positive-pension-happiness-money-saving-retirement-financial-118207382.jpg);"></div>
<article>
<h1>title</h1>
<p></p>
<span>content</span>
</article>
</a>
</div>
<div class="item-7">
<a href="#" class="card">
<div class="thumb" style="background-image: url(https://thumbs.dreamstime.com/z/positive-pension-happiness-money-saving-retirement-financia-positive-pension-happiness-money-saving-retirement-financial-118207382.jpg);"></div>
<article>
<h1>title</h1>
<p></p>
<span>content</span>
</article>
</a>
</div>
</div>
Change flex-direction: column; to flex-direction: row; on card. Then you just have to define a width for thumb because you are using it as a background image. So I set width: 100%; to thumb.
html {
background: #f5f7f8;
font-family: 'Roboto', sans-serif;
-webkit-font-smoothing: antialiased;
padding: 20px 0;
}
.band {
width: 90%;
max-width: 1240px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: auto;
grid-gap: 20px;
}
#media only screen and (min-width: 500px) {
.band {
grid-template-columns: 1fr 1fr;
}
.item-1 {
grid-column: 1/ span 2;
}
.item-1 h1 {
font-size: 30px;
}
}
#media only screen and (min-width: 850px) {
.band {
grid-template-columns: 1fr 1fr 1fr 1fr;
}
}
/* card */
.card {
min-height: 100%;
background: white;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: row;
flex-flow: row;
text-decoration: none;
color: #444;
position: relative;
top: 0;
transition: all .1s ease-in;
}
.card:hover {
top: -2px;
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.2);
}
.card article {
padding: 20px;
display: flex;
flex: 1;
justify-content: space-between;
flex-direction: column;
}
.card .thumb {
padding-bottom: 60%;
background-size: cover;
background-position: center center;
}
.card p {
flex: 1;
/* make p grow to fill available space*/
line-height: 1.4;
}
/* typography */
h1 {
font-size: 20px;
margin: 0;
color: #333;
}
.card span {
font-size: 12px;
font-weight: bold;
color: #999;
text-transform: uppercase;
letter-spacing: .05em;
margin: 2em 0 0 0;
}
.thumb {
width: 100%;
}
<div class="support-grid"></div>
<div class="band">
<div class="item-4">
<a href="#" class="card">
<div class="thumb" style="background-image: url(https://thumbs.dreamstime.com/z/positive-pension-happiness-money-saving-retirement-financia-positive-pension-happiness-money-saving-retirement-financial-118207382.jpg);"></div>
<article>
<h1>title</h1>
<p></p>
<span>content</span>
</article>
</a>
</div>
<div class="item-5">
<a href="#" class="card">
<div class="thumb" style="background-image: url(https://thumbs.dreamstime.com/z/positive-pension-happiness-money-saving-retirement-financia-positive-pension-happiness-money-saving-retirement-financial-118207382.jpg);"></div>
<article>
<h1>title</h1>
<p></p>
<span>content</span>
</article>
</a>
</div>
<div class="item-6">
<a href="#" class="card">
<div class="thumb" style="background-image: url(https://thumbs.dreamstime.com/z/positive-pension-happiness-money-saving-retirement-financia-positive-pension-happiness-money-saving-retirement-financial-118207382.jpg);"></div>
<article>
<h1>title</h1>
<p></p>
<span>content</span>
</article>
</a>
</div>
<div class="item-7">
<a href="#" class="card">
<div class="thumb" style="background-image: url(https://thumbs.dreamstime.com/z/positive-pension-happiness-money-saving-retirement-financia-positive-pension-happiness-money-saving-retirement-financial-118207382.jpg);"></div>
<article>
<h1>title</h1>
<p></p>
<span>content</span>
</article>
</a>
</div>
</div>
Start by focusing on these two areas:
In your code, the flex container is set to flex-direction: column. This makes your image and the article (i.e., the flex items) stack vertically. Remove this column setting so that the items can line up in a row (which is the default setting).
The flex container will work better if you render the item with HTML (using the img tag) as opposed to CSS (using the background-image property). It will work even better if you wrap the img in a figure, div or other HTML element, as images seem to be problematic for some browsers when they're flex items. The common solution is to make the wrapper a flex item.
.card {
display: flex;
/* flex-direction: column; */
}
div {
width: 200px;
}
img {
width: 100%;
height: auto;
}
.card article {
padding: 20px;
}
<a href="#" class="card">
<div>
<img src="https://thumbs.dreamstime.com/z/positive-pension-happiness-money-saving-retirement-financia-positive-pension-happiness-money-saving-retirement-financial-118207382.jpg">
</div>
<article>
<h1>title</h1>
<p></p>
<span>content</span>
</article>
</a>
Setting the .card class flex-direction to this:
.card {
flex-direction: row;
}
and adding: flex: 1 0 1%; width:1%; to article and .thumb should get you started.
Related
I would like to achieve circle cuts/hollows in the layer that covers the background images.
I have the background image covered with white tint (opacity 60%).
On the background, I have 3 circles that include text.
How can I cut "rings" in the white tint?
I would like to make hollows/cuts in the white tint like here:
My code looks now as below:
body {
margin: 0;
}
.block {
position: relative;
width: 100%;
}
.bg {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -3;
}
.bg:before {
content: "";
background: #ffffff;
opacity: 0.6;
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
}
.bg img {
display: block;
object-fit: cover;
object-position: center;
width: 100%;
height: 100%;
}
.wrapper {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
gap: 0 30px;
}
.item {
background: #aaaaaa;
width: 150px;
height: 150px;
border-radius: 100%;
display: flex;
flex-direction: columns;
justify-content: center;
align-items: center;
padding: 10px;
}
.item h2 {
font-family: Arial, sans-serif;
font-size: 15px;
color: #000000;
text-align: center;
margin: 0;
}
<section class="block">
<div class="bg">
<img src="https://i.picsum.photos/id/98/1920/1080.jpg?hmac=38vHAR4QCfR9YGpaasbQ0h390ZJnDlnQqzv3xTDF6ik" alt="" />
</div>
<div class="wrapper">
<div class="item">
<div class="item__content">
<h2>Heading 1</h2>
</div>
</div>
<div class="item">
<div class="item__content">
<h2>Heading 2</h2>
</div>
</div>
<div class="item">
<h2>Heading 3</h2>
</div>
</div>
</section>
You can do it like below. I have simplified the code as well:
body {
margin: 0;
}
section {
min-height: 100vh;
/* a grid container with 3 columns*/
display: grid;
grid-template-columns: 1fr 1fr 1fr;
/* the image as background */
background: url(https://i.picsum.photos/id/98/1920/1080.jpg?hmac=38vHAR4QCfR9YGpaasbQ0h390ZJnDlnQqzv3xTDF6ik) center/cover;
}
.item {
overflow: hidden; /* hide the overflow of the shadow */
/* center the heading */
display: grid;
place-items: center;
/**/
}
.item h2 {
width: 80%; /* adjust this to control the size */
aspect-ratio: 1; /* keep it a perfect circle */
box-sizing: border-box;
border-radius: 50%;
/* center the content of the heading */
display: grid;
place-items: center;
/**/
padding: 20px; /* this will control the inner space */
background: rgb(255 255 255/60%) content-box; /* color only the content area */
box-shadow: 0 0 0 100vmax rgb(255 255 255/60%); /* a big box-shadow */
}
<section>
<div class="item">
<h2>Heading 1</h2>
</div>
<div class="item">
<h2>Heading 2</h2>
</div>
<div class="item">
<h2>Heading 2</h2>
</div>
</section>
My 3x3 grid is not scaling as it should. Box 1, 5 and 9 contain some form of text, and the rest of them are pictures. When scaling down, the box with photos are displaying an excessive amount of white, and the ones with text are displaying an excessive amount of blue. I have no idea what is causing this to happen.
I am also looking for a way to center my text in its designated squares. Left aligned, but still centered. I have no idea how to apply both.
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 1em;
grid-auto-rows: 1fr;
text-align: left;
color: white;
font-size: 14px;
font-family: Open Sans, sans-serif;
}
/* .grid>div {
background: #2b5eaf;
padding: 1em;
} */
/* .grid>div:nth-child(odd) {
background: #2b5eaf;
} */
.box-1,
.box-5,
.box-9 {
background: #2b5eaf;
color: white;
}
.button {
border: none;
color: white;
padding: 16px 50px;
text-align: center;
text-decoration: none;
font-size: 14px;
transition-duration: 0.4s;
cursor: pointer;
border-radius: 12px;
}
.group1 {
padding: 48px;
justify-content: center;
}
h1 {
font-size: 30px;
}
p {
font-size: 14px;
}
.box-5 {
display: flex;
flex-direction: column;
align-items: center;
}
.button2 {
background-color: white;
color: black;
border: 2px solid #008CBA;
}
.button2:hover {
background-color: #008CBA;
color: white;
}
.photo>img {
object-fit: cover;
width: 100%;
max-height: 100%;
}
.photo {
width: 100%;
height: auto;
}
/* TABLET VIEW */
#media only screen and (min-width: 759px) and (max-width: 1279px) {
.grid {
grid-template-columns: repeat(2, 1fr);
text-align: left;
grid-gap: 0;
}
.grid>div {
height: 100%;
}
.box-2,
.box-6,
.box-7 {
display: none;
}
.box-8 {
grid-column: 2;
grid-row: 3;
}
.box-9 {
grid-column: 1;
}
h1 {
font-size: 24px;
}
}
/* MOBILE VIEW */
#media only screen and (max-width: 759px) {
.grid {
grid-template-columns: 1fr 1fr;
text-align: left;
grid-gap: 0;
}
.box-1 {
grid-row: 3;
grid-column: 1/3;
}
.box-2 {
grid-row: 2;
grid-column: 1;
}
.box-3 {
grid-row: 2;
grid-column: 2;
}
.box-5 {
grid-row: 1;
grid-column: 1/3;
}
.box-7,
.box-8,
.box-9 {
display: none;
}
}
<div class="grid">
<!-- CLASS NUMBER READ LEFT TO RIGHT FROM DESKTOP VIEW -->
<div class="box-1">
<div class="group1">
<h1 class="quote" style="color:#ffffff" ;>"Lingerie is not about seducing men; It's about embracing womanhood"</h1><br><br>
<p style="color:#ffffff" ;>- Dita Von Teese</p>
</div>
</div>
<div class="box-2">
<img class="photo" src="https://i.imgur.com/p5IOrlS.png" alt="">
</div>
<div class="box-3">
<img class="photo" src="https://i.imgur.com/JKKqZjj.png" alt="">
</div>
<div class="box-4">
<img class="photo" src="https://i.imgur.com/pI3g39l.png" alt="">
</div>
<div class="box-5">
<h1 style="color:#ffffff" ;>Discover Something Sexy In You</h1>
<a class="button button2" href="https://www.subbly.co/checkout/buy/112646">Take Style Quiz</a>
</div>
<div class="box-6">
<img class="photo" src="https://i.imgur.com/2mVzhR6.png" alt="">
</div>
<div class="box-7">
<img class="photo" src="https://i.imgur.com/bIcsE4S.png" alt="">
</div>
<div class="box-8">
<img class="photo" src="https://i.imgur.com/LnUV9eF.png" alt="">
</div>
<div class="box-9">
<div class="group1">
<h1 style="color:#ffffff" ;>"My wife and I absolute LOVE our SeductiveBox subscription! This bring more excitement to our love life. Plus this is the only subscription that gets unwrapped TWICE!"</h1><br><br>
<p style="color:#ffffff" ;>- Wendy S.</p>
</div>
</div>
</div>
flex and grid works wonderfully together. Simply add display: flex; to your photos (and use proper selectors - .photo > img is not a proper selector as they are the same element - use img.photo instead). Also use height: 100%; for them to scale properly.
On the boxes where you want to center the text, use flex and its properties align-items: center; to center vertically and justify-content: center; to center horizontally.
I haven't done any styling in the media-query, you can use the same logic as above if you want.
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 1em;
grid-auto-rows: 1fr;
text-align: left;
color: white;
font-size: 14px;
font-family: Open Sans, sans-serif;
}
/* .grid>div {
background: #2b5eaf;
padding: 1em;
} */
/* .grid>div:nth-child(odd) {
background: #2b5eaf;
} */
.box-1,
.box-5,
.box-9 {
background: #2b5eaf;
color: white;
display: flex;
align-items: center;
justify-content: center;
}
.button {
border: none;
color: white;
padding: 16px 50px;
text-align: center;
text-decoration: none;
font-size: 14px;
transition-duration: 0.4s;
cursor: pointer;
border-radius: 12px;
}
.group1 {
padding: 48px;
justify-content: center;
}
h1 {
font-size: 30px;
}
p {
font-size: 14px;
}
.box-5 {
display: flex;
flex-direction: column;
align-items: center;
}
.button2 {
background-color: white;
color: black;
border: 2px solid #008CBA;
}
.button2:hover {
background-color: #008CBA;
color: white;
}
img.photo {
display: flex;
object-fit: cover;
width: 100%;
height: 100%;
}
/*.photo {
width: 100%;
height: auto;
}*/
/* TABLET VIEW */
#media only screen and (min-width: 759px) and (max-width: 1279px) {
.grid {
grid-template-columns: repeat(2, 1fr);
text-align: left;
grid-gap: 0;
}
.grid>div {
height: 100%;
}
.box-2,
.box-6,
.box-7 {
display: none;
}
.box-8 {
grid-column: 2;
grid-row: 3;
}
.box-9 {
grid-column: 1;
}
h1 {
font-size: 24px;
}
}
/* MOBILE VIEW */
#media only screen and (max-width: 759px) {
.grid {
grid-template-columns: 1fr 1fr;
text-align: left;
grid-gap: 0;
}
.box-1 {
grid-row: 3;
grid-column: 1/3;
}
.box-2 {
grid-row: 2;
grid-column: 1;
}
.box-3 {
grid-row: 2;
grid-column: 2;
}
.box-5 {
grid-row: 1;
grid-column: 1/3;
}
.box-7,
.box-8,
.box-9 {
display: none;
}
}
</h1>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title></title>
</head>
<body>
<div class="grid">
<!-- CLASS NUMBER READ LEFT TO RIGHT FROM DESKTOP VIEW -->
<div class="box-1">
<div class="group1">
<h1 class="quote" style="color:#ffffff" ;>"Lingerie is not about seducing men; It's about embracing womanhood"</h1><br><br>
<p style="color:#ffffff" ;>- Dita Von Teese</p>
</div>
</div>
<div class="box-2">
<img class="photo" src="https://i.imgur.com/p5IOrlS.png" alt="">
</div>
<div class="box-3">
<img class="photo" src="https://i.imgur.com/JKKqZjj.png" alt="">
</div>
<div class="box-4">
<img class="photo" src="https://i.imgur.com/pI3g39l.png" alt="">
</div>
<div class="box-5">
<h1 style="color:#ffffff" ;>Discover Something Sexy In You</h1>
<a class="button button2" href="https://www.subbly.co/checkout/buy/112646">Take Style Quiz</a>
</div>
<div class="box-6">
<img class="photo" src="https://i.imgur.com/2mVzhR6.png" alt="">
</div>
<div class="box-7">
<img class="photo" src="https://i.imgur.com/bIcsE4S.png" alt="">
</div>
<div class="box-8">
<img class="photo" src="https://i.imgur.com/LnUV9eF.png" alt="">
</div>
<div class="box-9">
<div class="group1">
<h1 style="color:#ffffff" ;>"My wife and I absolute LOVE our SeductiveBox subscription! This bring more excitement to our love life. Plus this is the only subscription that gets unwrapped TWICE!"</h1><br><br>
<p style="color:#ffffff" ;>- Wendy S.</p>
</div>
</div>
</div>
</body>
</html>
I'm having trouble getting max-width to work in IE. Is there a way to get max-width to work on IE?
This is what it looks like on other browsers:
enter image description here
This is what it looks like on IE:
enter image description here
here's HTML code
<div class="grid menu-content" id="menu1-content">
<article>
<div class="photo" style="background-image: url(img/test.jpg);">
</div>
<div class="text">
<div class="company-name">Name</div>
<div class="company-description">Basdfasdfasdf
</div>
</div>
<div class="founders">
<div class="founder">
<div class="picture"><img src="img/test.jpg" alt="asdf"></div>
<div class="name">FIRSTNAME LASTNAME</div>
</div>
<div class="founder">
<div class="picture"><img src="img/test.jpg" alt="sdf"></div>
<div class="name">FIRSTNAME LASTNAME</div>
</div>
</div>
</article>
<article>
<div class="photo" style="background-image: url(img/test.jpg);"></div>
<div class="text">
<div class="company-name">name</div>
<div class="company-description">asdfasdf
</div>
</div>
<div class="founders">
<div class="founder">
<div class="picture"><img src="img/breadfinance-founder.jpg" alt="Bread Finance Founder JOSH ABRAMOWITZ
"></div>
<div class="name">BEN JIN
</div>
</div>
</div>
</article>
<article>
<div class="photo" style="background-image: url(img/test.jpg);"></div>
<div class="text">
<div class="company-name">asdfasdf</div>
<div class="company-description">asdfasdfasdf
</div>
</div>
<div class="founders">
<div class="founder">
<div class="picture"><img src="img/test.jpg" alt="asdf"></div>
<div class="name">KATIE KIM</div>
</div>
</div>
</article>
<article>
<div class="photo" style="background-image: url(img/test.jpg);"></div>
<div class="text">
<div class="company-name">asdfasdf</div>
<div class="company-description">asdfasdf
</div>
</div>
<div class="founders">
<div class="founder">
<div class="picture"><img src="img/test.jpg" alt="asdfasdf"></div>
<div class="name">DEBBIE KIM</div>
</div>
</div>
</article>
</div>
here's CSS
.name {
font-size: 12px;
letter-spacing: 2.2px;
margin-left: 17px;
}
.founder img {
width: 22px;
}
.founder {
margin-bottom: -5px;
}
article .picture {
max-width: 22px;
}
.
.company-name {
margin-top: 20px;
margin-bottom: 1px;
font-size: 22.5px;
}
.company-description {
font-size: 21px;
line-height: 1.8;
letter-spacing: 0.5px;
margin-bottom: 6px ;
}
.founders {
position: absolute;
}
.founder {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin, padding: 0px;
}
.name {
letter-spacing: 2.2px;
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
line-height: 1.6;
}
.picture {
-webkit-box-flex: 0;
-ms-flex: 0 0 22px;
flex: 0 0 22px;
margin: 0;
}
.founder img {
margin-top: 0;
margin-bottom: 0;
vertical-align: middle;
}
.founders {
top: 99%;
}
#media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* IE10+ CSS */
.grid article {
-ms-flex: 0 0 250px;
margin-right: 20px;
margin-bottom: 150px;
-ms-flex-pack: start;
}
.grid article {
-ms-flex: 0 0 250px;
margin-right: 20px;
margin-bottom: 150px;
-ms-flex-pack: start;
}
}
some more css that's probably not relevant
.grid {
display: -ms-flexbox;
-ms-flex-wrap: wrap;
display: grid;
-webkit-box-pack: start;
justify-content: start;
justify-content: space-between;
row-gap: 100px;
}
.grid article {
-ms-flex: 0 0 250px;
-ms-flex-pack: start;
}
.grid .photo {
width: 100%;
background-size: contain;
background-position: center;
}
.grid .photo:after {
content: "";
display: block;
padding-bottom: 100%;
}
.grid a {
display: block;
text-decoration: none;
color: inherit;
}
.grid article {
position: relative;
}
.grid {
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
grid-row-gap: 100px;
grid-column-gap: 50px;
}
It looks like you have created this new thread for the same issue that you had asked for before.
I have tested the sample code and found that -ms-flex: 1; and flex: 1; in the .name class is causing this issue.
IE 11 has partial support for the Flex due to some known issues. This can be a possible reason for this issue.
The issue can be fixed by commenting or removing the flex from the .name class.
.name class:
.name {
letter-spacing: 2.2px;
-webkit-box-flex: 1;
/*-ms-flex: 1;
flex: 1;*/
line-height: 1.6;
}
Output:
I have one flexbox with two rows and min-height. The right row has another flex with 2 columns with justify-content space between.
It works perfectly fine in Chrome but it does not fill the min-height in IE. There are many questions about it but none of them worked for me. Please note I have different styles of this where image is on top, bottom or right. I need to expand both content and image to fill the entire card in IE.
Here is the code.
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.card-image {
width: 100%;
background-size: cover;
width:80px;
height: 100%;
background-repeat: no-repeat;
background-position: 50% 50%;
background-image: url("https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg");
}
<div class='card-wrap'>
<a href='#'>
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</a>
</div>
Image from IE
Its a bug in IE 10-11. In IE 10-11, min-height declarations on flex containers work to size the containers themselves, but their flex item children do not seem to know the size of their parents. They act as if no height has been set at all.
More info: https://github.com/philipwalton/flexbugs#flexbug-3
Workaround
Simply wrap the flex container (here it div with classname card) with another flex-container having flex direction column
.ie-fix-wrapper{
display: flex;
flex-direction:column;
}
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.card-image {
width: 100%;
background-size: cover;
width:80px;
height: 100%;
background-repeat: no-repeat;
background-position: 50% 50%;
background-image: url("https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg");
}
<div class='card-wrap'>
<a href='#'>
<div class="ie-fix-wrapper">
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</div>
</a>
</div>
The solution provided by #Soothran works well. There is also alternative solution that is quicker to implement - inherit min-height in the children. In this case of the code above:
.image-wrap {
min-height: inherit;
}
.card-content {
min-height: inherit;
}
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
min-height: inherit;
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.image-wrap {
min-height: inherit;
}
.card-image {
width: 100%;
width:80px;
height: 100%;
background: black;
}
<div class='card-wrap'>
<a href='#'>
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</a>
</div>
You need to wrap any flex-direction:column inside a flex-direction:row
(or just display:flex for simple)
I have this situation:
<div class="slot_twoimages">
<article class="slot image">
<img src="https://via.placeholder.com/560x441" />
</article>
<article class="slot image">
<img src="https://via.placeholder.com/560x441" />
</article>
<article class="slot text">
<div class="headline">HEADLINE</div>
</article>
with this style:
.slot_twoimages {
height: auto;
background-image: linear-gradient(120deg, yellow, pink);
display: flex;
flex-wrap: wrap;
justify-content: center;
align-content: center;
.slot.image {
//margin: 121px 40px 64px;
display: inline-block;
flex: 50%;
//DA RIMUOVERE
img {
max-width: 560px;
max-height: 441px;
}
}
.slot.text {
width: 100%;
display: block;
text-align: center;
margin: 0 30% 88px;
margin-bottom: 88px;
.headline {
font-size: 29px;
margin-bottom: 50px;
letter-spacing: -0.015em;
padding-top: 24px;
padding-bottom: 10px;
}
}
}
Now, I want to center two images with flexbox and I need to center slot text under the two images. I need to mantain the images in the same position and it's necessary the image scaling. I can't modify the DOM.
Here is my codepen: https://codepen.io/andrew_88/pen/rqpxMP
CSS part
.slot_twoimages {
height: auto;
background-image: linear-gradient(120deg, yellow, pink);
display:grid;
grid-template-columns: 0.5fr 1fr 0.5fr;
}
.slot_twoimages .slot.image {
}
.slot_twoimages .slot.image img {
max-height: 441px;
}
.slot_twoimages .slot.text {
width: 100%;
display: block;
text-align: center;
margin-bottom: 88px;
}
.slot_twoimages .slot.text .headline {
font-size: 29px;
}
#image1
{
grid-column: 2;
}
#image2
{
grid-column: 2;
}
#text1
{
grid-column: 2;
text-align: center
}
HTML part
<div class="slot_twoimages">
<div id="image1" class="slot image">
<img src="https://via.placeholder.com/560x441" />
</div>
<div id="image2" class="slot image">
<img src="https://via.placeholder.com/560x441" />
</div>
<div id="text1" class="slot text">
<div class="headline">HEADLINE</div>
</div >
</div>
Result :
https://codepen.io/richardpariath3/pen/oapbRB
Please note that I made use of CSS Grids