I managed to use the Flexible Box Layout Module for a lot of things, however when it comes to paragraphs I'm experiencing this issue:
When I use a small amount of text everything works as expected:
When I use a large amount of text the layout breaks:
Here is the code I am using:
body {
width: 90%;
margin: 3em auto;
background-color: #aaa;
}
section {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
border: 1px solid black;
}
.title {
flex: 1 0 100%;
text-align: center;
background-color: #eee;
}
.image {
flex: 0 0 auto;
background-color: #ccc;
}
.image img {
display: block;
max-height: 100%;
max-width: 100%;
}
.text {
flex: 6 0 auto;
background-color: #96AED1;
}
<section>
<div class="title">
<h1>Title here</h1>
</div>
<div class="image">
<img src="http://www.macovei-sculptor.ro/img.jpg">
</div>
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer felis velit, ullamcorper eu ornare sed, vulputate quis diam. Duis ultrices rutrum sapien, in condimentum nibh sagittis sit amet. Morbi sit amet rhoncus dui, at pharetra nisi. Nunc et
lacus porttitor, pretium nisl at, sollicitudin velit. Donec felis nisl, consequat vitae egestas vestibulum, egestas non tortor. Cras mattis non sem nec aliquam. Sed dignissim sit amet sapien vitae feugiat. Pellentesque vel luctus ante, quis ornare
purus. Nulla in arcu sapien. Aenean tempor arcu ac lacinia pellentesque. Quisque vulputate maximus augue, non aliquet ligula gravida in. Donec a leo justo. Integer velit eros, blandit sit amet elit eget, efficitur mollis nulla. Suspendisse tempor
ligula facilisis scelerisque ullamcorper. Ut vehicula ligula ipsum, cursus condimentum sapien pretium ac.</p>
</div>
</section>
Why is the <p>
tag not wrapping properly when using a large amount of text?
As you only want the text itself to wrap you need to use flex-wrap: nowrap; to keep . right on the same line. The text will automatically wrap when there is not enough space.
The flex-wrap property allows enabling the control direction in which lines are stacked. It is used to designate a single line or multi-line format to flex items inside the flex container.
If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).
The proper solution is either to put
white-space: initial;
or
min-width: 0;
Check out the link here
*I am aware the link is about truncating texts. However, the same solution applies to wrap the texts around.
the .text's parent has flex-direction: row, so .text should have shrink set on 1 otherwise the text inside won't wrap
body {
width: 90%;
margin: 3em auto;
background-color: #aaa;
}
section {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
border: 1px solid black;
}
.title {
flex: 1 0 100%;
text-align: center;
background-color: #eee;
}
.image {
flex: 0 0 auto;
background-color: #ccc;
}
.image img {
display: block;
max-height: 100%;
max-width: 100%;
}
.text {
flex: 6 1 auto; /* FLEX-SHRINK: 1; */
background-color: #96AED1;
}
<section>
<div class="title">
<h1>Title here</h1>
</div>
<div class="image">
<img src="http://www.macovei-sculptor.ro/img.jpg">
</div>
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer felis velit, ullamcorper eu ornare sed, vulputate quis diam. Duis ultrices rutrum sapien, in condimentum nibh sagittis sit amet. Morbi sit amet rhoncus dui, at pharetra nisi. Nunc et
lacus porttitor, pretium nisl at, sollicitudin velit. Donec felis nisl, consequat vitae egestas vestibulum, egestas non tortor. Cras mattis non sem nec aliquam. Sed dignissim sit amet sapien vitae feugiat. Pellentesque vel luctus ante, quis ornare
purus. Nulla in arcu sapien. Aenean tempor arcu ac lacinia pellentesque. Quisque vulputate maximus augue, non aliquet ligula gravida in. Donec a leo justo. Integer velit eros, blandit sit amet elit eget, efficitur mollis nulla. Suspendisse tempor
ligula facilisis scelerisque ullamcorper. Ut vehicula ligula ipsum, cursus condimentum sapien pretium ac.</p>
</div>
</section>
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