I’ve got two columns that I want equally spaced and with some blank space between their borders. I’ve added css to make it responsive so that the columns are stacked vertically when the screen size gets to be too small, but when the columns are stacked on top of each other, they are no longer centered on the page. How do I fix this?
.row {
margin: 5%;
}
/* Create two equal floating columns */
.column {
text-align: center;
width: 40%;
padding: 4%;
border-radius: 20px;
color: #f0e7e0;
background: #777a44;
margin-bottom: 10%;
margin-left: 5%;
margin-right: 5%;
}
/* Responsive layout */
@media screen and (max-width: 600px) {
.column {
width: 100%;
}
}
<div class="row">
<div class="column">
<h2>Inquiries?</h2>
<br />
<p>Text</p>
</div>
<div class="column">
<h2>Want to connect?</h2>
<br />
<p>Text</p>
</div>
</div>
2
Answers
Simply change margins to classic
margin-[left|right]: auto;
Have you considered switching to a more modern approach to css layouts. For example you could use flex-box to manage your responsive breakpoints like so:
This allows you "to make it responsive so that the columns are stacked vertically when the screen size gets to be too small".