I have a grid of circles, and in each circle I am trying to display text that is vertically centered. No matter what I try, nothing has worked so far.
Code is on codepen: https://codepen.io/slurmclassic/pen/bGvBJPJ
My HTML looks this this:
<div class="grid">
<a class="grid-item" href = 'linka'><span>Text A</span></a>
<a class="grid-item" href = 'linkb'><span>Text B</span></a>
<div class="grid-item" ><span>Company Logo</span></div>
<a class="grid-item" href = 'linkc'><span>Text C</span></a>
<a class="grid-item" href = 'linkd'><span>Text D</span></a>
</div>
My CSS looks like this:
.grid {
width: 100%;
max-width: 500px;
margin: 0 auto;
background: #CCC;
}
.grid::after {
content: "";
display: block;
clear: both;
}
.grid-item {
text-decoration: none;
overflow: hidden;
width: 48%;
padding-bottom: 48%;
background-color: rgba(124, 139, 224, 0.8);
border-radius: 50%;
float: left;
margin: 1%;
margin-top: -4%;
color: black;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
.grid-item > span {
color: black;
text-align: center;
display: table-cell;
vertical-align: middle;
align-items: center;
justify-content: center;
text-align: center;
}
.grid-item:nth-child(1),
.grid-item:nth-child(2) {
margin-top: 1%;
}
.grid-item:nth-child(3n + 3) {
margin-left: 25%;
}
.grid-item:nth-child(3n + 4) {
clear: left;
}
I have tried to put the text in spans so that I can try to attack the problem separately from the 'grid-item' class but that hasn't helped.
I could brute force by applying a transform that shifts the text down but there must be a better way to do this.
I've tried text-align: center, align-items: center, justify-content: center, vertical-align: middle. I've tried setting the line-height equal to the font-size but that didn't help either.
Any ideas would be appreciated, and any demonstratable solutions too, thanks.