I'm having trouble vertically aligning the text within an anchor tag that has a height and background color set. The goal is to have equal amounts of space above and below the text, but currently all the extra height is being added below the text. I've tried various methods such as using padding, applying display: table and table-cell properties, and setting a line-height, but haven't had success yet.
You can see the issue in the provided codepen link, which demonstrates what I'm trying to achieve:
HTML:
<div class="border">
<a href="#">Link</a>
</div>
SCSS:
.border {
display: inline-block;
width: 200px;
height: 70px;
border: 2px solid #2BD6C5;
position: relative;
}
a {
display: inline-block;
vertical-align: middle;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
height: 80%;
width: 90%;
text-align: center;
color: #FFF;
font: 24px sans-serif;
text-decoration: none;
background-color: #2BD6C5;
transition: 250ms ease-in;
&:hover {
width: 100%;
height: 100%;
}
}