11
Well, I created a class called .btn
, where I wanted to use it so much to button
as for a
. So I pushed a few things in this class, to reset the original style, both of the button
as in the a
.
For example, in the a
I removed the text-decoration
. In the button
, forced the change of background
and border
. So far so good.
The problem is that I’m noticing that the element button
, even using the -webkit-appearence: none
, has a different behavior in relation to the alignment of the internal text, according to the test below:
.btn{
border: 1px solid transparent;
padding: 10px 20px;
box-shadow: 0 1px 2px 0px #666;
outline: none;
border-radius: 4px;
background-color: #efefef;
cursor: pointer;
transition: box-shadow .1s ease-out, border-color .3s linear;
font-weight: bold;
box-sizing: border-box;
vertical-align: top;
display: inline-block;
min-height: 55px;
font-size: 14px;
text-decoration: none;
color: #222;
background-image: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
font-family: Arial;
}
<button class="btn">
Eu sou um <Button>
</button>
<a class="btn">
Eu sou um <A>
</a>
I’ll put the image too, to show how the rendering looked in my Google Chrome:
Now I have my doubts:
What property makes the
button
align the texts in the middle, while thea
nay?Is there a way to reset this standard alignment of
button
? My intention was to leave the two centralized, but more importantly than that, I want to know if there is a property of thebutton
made it align to the center.
Observing: The question is not only intended to know how to align the text to the center, but to know in depth about what caused the difference mentioned above, since I used the same style for all.
Observation 2: I could use inline-flex
and match justify-content: center; align-itens: center
, but that’s not the answer I want, because I’m already putting it in the question. I want to know specifically about the details presented above, and not just a "support for the alignment problem"
Already checked which styles are assigned by <button> and <a> by default in any browser.
– Jorge Costa
@Jorgecosta I copied all user-agent styles and applied to the selector
a {...}
nothing happens, this is behavior of the element Button as if isolating the text to, different from the A that the internal text accompanies thevertical-align: top
– Guilherme Nascimento
but found that the button has line-height, in safari on macOS is line-height: 13px;
– Jorge Costa
@Jorgecosta up copying user-agent line-height to
<button>
the result is the same.– Guilherme Nascimento
To test remove min-height: 55px; and place line-height: 3; padding: 0px;
– Jorge Costa
@Jorgecosta if you put
min-height: 1000px
on the button, it gets everything in between, in the same way. I don’t think it’s just theline-height
.– Wallace Maxters
Dear @Jorgecosta take the
min-height
does not explain how the text in<button>
aligns vertically to the center. Here nobody is looking for solutions how to solve, but rather understand why this occurs, as the author of the question already explained in his own question.– Guilherme Nascimento
Yeah I’m trying to figure it out too
– Jorge Costa
Dear @Jorgecosta I understand, but your comments were all about strip this, does that, ends up making understand that this trying to apply solutions and not trying to understand the behavior of the box-model: https://www.w3.org/TR/CSS2/box.html, but I think we are already clear of everything :)
– Guilherme Nascimento
I was checking what the browser itself applies by default, if to find the solution I would limit myself to applying the solutions already found in frameworks such as bootstrap. But since you are clear on the question I would appreciate you putting a full answer to the question and so share with all.
– Jorge Costa