I’m trying to make 4 boxes appear in two ways
-
On PC/a large display have all 4 boxes an equal size taking up 25% of the page each
-
On smaller displays (once the boxes start overlapping each other), have the boxes shown in a column, with each box expanding to fill the width of the screen.
<div class="flex-container">
<p id="box" style="text-align: center;"><strong><a >Box 1</a></strong></p>
<p id="box" style="text-align: center;"><strong><a >Box 2</a></strong></p>
<p id="box" style="text-align: center;"><strong><a >Box 3 </a></strong></p>
<p id="box" style="text-align: center;"><strong><a >Box 4 </a></strong></p>
</div>
.flex-container{
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: stretch;
}
@media screen and (max-width: 600px){
.flex-container{
flex-direction: column;
}
}
#box{
border: 15px solid blue;
padding: 15px;
}
2
Answers
In this code, I replaced the duplicate id="box" attributes with class="box". Then, I used the .box class selector in the CSS code to target those elements. This ensures that the styling is applied consistently to all the boxes.
First of all you cannot have more than one element with the same id in an HTML document. So change all the ids(box) to class.
Add
.box{width: 100%}
or 25% above the media-query. It will make the box share same width in desktop.