I have elements that are currently being used as buttons, but I want to switch them out for actual button tags. This would improve accessibility and allow keyboard navigation using the tab key to focus on my buttons. Each button contains a centered SVG image. However, when I replaced the div tags with button tags, the images ended up off-center. (They also turned gray, but I easily fixed that by setting the background color to transparent.)
Can anyone explain why these two buttons are centering differently? How can I ensure that the one on the left is centered properly in both horizontal and vertical directions while maintaining its status as a proper button element?
Thank you.
.control-panel {
border: 1px solid #0000;
display: flex;
justify-content: space-between;
}
.button {
border: 1px solid #000;
border-radius: 5px;
box-sizing: border-box;
background-color: transparent;
align-items: center;
cursor: pointer;
}
svg {
background-color: #0f84;
}
<div class="control-panel" style="width: 100px;">
<button class="button" style="height: 39px; width: 39px;"> <!-- BUTTON, BUT NOT CENTERED -->
<svg style="height: 37px; width: 37px;" viewBox="-18.5 -18.5 37 37" xmlns="http://www.w3.org/2000/svg"><path d="M12,-12 L12,12 L-12,12 L-12,-12 Z" stroke="#000" fill="none" stroke-width="1.5"></path></svg>
</button>
<div class="button" style="height: 39px; width: 39px;">
<!-- DIV, BUT CENTERS CORRECTLY -->
<svg style="height: 37px; width: 37px;" viewBox="-18.5 -18.5 37 37" xmlns="http://www.w3.org/2000/svg"><path d="M12,-12 L12,12 L-12,12 L-12,-12 Z" stroke="#000" fill="none" stroke-width="1.5"></path></svg>
</div>
</div>