I have 5 columns, I have them as table as it was the easiest way for me to code it.
I want to make them stack on mobile view. How do I go about doing this?
The format I have is:
#container {
display: table;
width: 100%;
table-layout: fixed;
padding: 10px;
}
.content {
display: table-cell;
text-align: center;
border: 5px solid black;
word-wrap: break-word;
}
.content img {
width: 100%;
height: 100%;
display: table-header-group;
}
<div id="container">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
</div>
Any help would be appreciated. I’ve tried setting the content class to width of 100% using the media query. I want them to stack if that is possible. I’m not sure where I am going wrong.
I tried using flexbox before the table method but ran into issues regarding the height when the screen size changed and this was easier for me to do, I just don’t know how to make it mobile responsive. Because it is not an actual table I am getting a little confused.
2
Answers
The absolute easiest way to do this, if you like your setup for desktop currently, is to wrap all your CSS above in a
@media
query for larger screens. Like@media (min-width: 768px) { ... all your CSS }
– this way, nothing on mobile will be affected by those styles. And by default,div
are block-level elements and will be 100% and stack.I made using grid, but I think it’s possible to use flex too: