After reading an article on Modern CSS grid solutions to common layout problems, I attempted to implement a two-way card layout as discussed.
You can view the demo on Codepen here.
However, when viewing on smaller screens, the paragraph text overlaps the image instead of wrapping into a new line if there is insufficient space:
https://i.sstatic.net/ARbfL.png
Do you have any suggestions on how to make the paragraph wrap when there is not enough space, rather than overlapping?
Code:
article {
display: grid;
grid-template-columns:
minmax(2rem, 1fr)
minmax(auto, 65ch)
minmax(2rem, 1fr);
}
/* Center all children */
article > * {
grid-column: 2;
}
/* Wider & centered images */
article > img {
grid-column: 1 / 4;
justify-self: center;
width: 100%;
max-width: 100ch;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
grid-template-rows: auto 1fr;
width: 100%;
}
<article>
<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>
<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>
</article>
<div class=grid>
<img src=https://via.placeholder.com/400x400 alt>
<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 aut...
...