How do I get the "x" to be vertically-aligned in the middle of the span?
.foo {
height: 50px;
border: solid black 1px;
display: inline-block;
vertical-align: middle;
}
<span class="foo">
x
</span>
How do I get the "x" to be vertically-aligned in the middle of the span?
.foo {
height: 50px;
border: solid black 1px;
display: inline-block;
vertical-align: middle;
}
<span class="foo">
x
</span>
The flexbox way:
.foo {
display: flex;
align-items: center;
justify-content: center;
height: 50px;
}
Just giving an alternative, in case you encapsulate your element in a flexible container (e.g.: display: flex):
align-self: center;
The vertical-align css attribute doesn't do what you expect unfortunately. This article explains 2 ways to vertically align an element using css.
Set padding-top to be an appropriate value to push the x down, then subtract the value you have for padding-top from the height.