I'm fairly new to CSS Flexbox but I'm trying to create a horizontal card, where an image is on the left, and text/buttons are on the right. When the site is scaled down (for mobile use), the row items should wrap and the image should sit on top of the text. I've tried setting the wrap property to wrap but it wraps for large screens when it should only wrap for smaller screens. See code below:
* {
margin: 0;
padding: 0;
}
#box {
padding: 20px;
}
img {
width: 200px;
}
#outer-container {
display: flex;
flex-wrap: wrap;
border: solid 1px;
width: 70%;
margin: auto;
}
#inner-container {
border: solid 1px;
display: flex;
justify-content: space-between;
flex-direction: column;
}
<div id="outer-container">
<img src="https://icatcare.org/app/uploads/2018/07/Thinking-of-getting-a-cat.png" alt="cat">
<div id="inner-container">
<div>
<h3>Heading</h3>
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div>
Other stuff
</div>
</div>
</div>
Should I attempt to use another approach (like Bootstrap's card layouts) or is there something obvious I'm missing?
Set a flex-basis
to the text container to control when the wrap should happen.
Open the below on full screen and resize to see:
* {
margin: 0;
padding: 0;
}
#box {
padding: 20px;
}
img {
width: 200px;
}
#outer-container {
display: flex;
flex-wrap: wrap;
border: solid 1px;
width: 70%;
margin: auto;
}
#inner-container {
border: solid 1px;
display: flex;
justify-content: space-between;
flex-direction: column;
flex-basis:500px;
flex-grow:1;
}
<div id="outer-container">
<img src="https://icatcare.org/app/uploads/2018/07/Thinking-of-getting-a-cat.png" alt="cat">
<div id="inner-container">
<div>
<h3>Heading</h3>
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div>
Other stuff
</div>
</div>
</div>
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