Assuming I have a piece of HTML that is structured like this:
-
After fiddling around with this for quite a while and getting a very helpful answer to another question that was related to this one, I managed to finally find a solution:
.linkgrid {
max-width: 50%;
display: table;
}
.gridentry:nth-child(odd) {
float: left;
width: 100%;
}
.gridentry:nth-child(even) {
width: 100%;
margin-left: 100%;
margin-right: -100%;
}
.gridentry:nth-child(even):after {
content: '';
display: block;
clear: left;
}
.gridentry > * {
display: block;
margin-bottom: 10px;
padding: 10px;
background-color: red;
text-align: center;
/* This is helpful if the texts get too long to break them "naturally": */
/* word-break: break-all; */
}
.gridentry:nth-child(odd) > * {
margin-right: 5px;
}
.gridentry:nth-child(even) > * {
margin-left: 5px;
}
.gridentry a {
color: white;
}