Reputation: 63
I have an image and a span in a button, and I've tried using:
but if I don't add a 1px padding-top to the image, it doesn't appear to be truly vertically aligned in the div, while the span text looks fine, and I can't figure out why.
HTML
<button class="metabolite-btn">
<img src="/images/metabolite/icon_question.svg" class="metabolite-btn__image">
<span class="metabolite-btn__text">代謝物質とは</span>
</button>
CSS
.main-wrapper {
.metabolite-btn {
width: $vw-size-115-width-375;
border-radius: 14px;
border: none;
height: 28px;
background-color: $main-color;
padding: 0 0 0 5px;
text-align: left;
cursor: pointer;
&__image {
width: $vw-size-20-width-375;
padding: 1px 0 0 0;
}
&__text {
font-size: $vw-size-12-width-375;
font-weight: bold;
color: $white;
line-height: 28px;
}
}
Upvotes: 0
Views: 191
Reputation: 5188
To align both the elements vertically, you need to add display:flex
and align-items: center
to parent which is your button (Shown below)
//CSS
button {
display: flex;
align-items: center;
}
Upvotes: 0