I know that there are many similar questions; however, I'm unable to center my example with those answers.
I have the following page structure:
.close-button {
margin-top: auto;
padding: 0;
cursor: pointer;
border: none;
border-radius: 5rem;
background: black;
color: white;
position: relative;
width: 5em;
height: 5em;
}
.close-button .mark {
position: absolute;
width: 100%;
height: 100%;
margin: 0;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<button class="close-button">
<div class="mark">+</div>
</button>
I want to center the textContent of the mark div in the middle of the created circle, as you can see my attempt with position: absolute
did not work. I also tried it with flex
, however, that also did not create the result I wanted to achieve. Furthermore, I also stumbled upon margin-collapse, but I doubt that it is the issue here.
How can I center my text vertically and horizontally in the created circle?
` element. And I don't believe `margin-top: auto; ` is ever useful if you are not using flex or grid.
– mrmonsieur Nov 28 '21 at 17:59