I have encountered an issue with my code where the .content
element, which has flex properties, appears cut off on small screens.
I want to avoid setting a fixed size because the text within it may vary in size.
The goal is for the background image to fill the height of large screens, while keeping the textual content centered on the right side. However, on smaller screens, the text should be displayed first and clearly visible before displaying the background image.
How can I ensure that the content remains visible and pushes the background image down on smaller screens? You can view the example here (adjust screen size).
html, body, .wrapper {
height: 100%;
padding: 0;
margin: 0;
}
.wrapper {
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 100%;
}
.background {
background: url('http://via.placeholder.com/800x600') no-repeat center center/cover;
display: flex;
flex: 1;
order: 2;
}
.content {
flex: 1;
order: 1;
padding: 3em;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
}
@media screen and (min-width: 768px) {
.wrapper {
flex-direction: row;
}
.background {
order: 1;
}
.content {
order: 2;
}
}