I am trying to center align link elements one below the other, inside a parent element where the elements take the minimum width and height like when using display:inline-block
.parent {
text-align: -moz-center;
text-align: -webkit-center;
text-align: -ms-center;
}
.parent a {
display:block;
width:-moz-fit-content;
width:-webkit-fit-content;
width:-ms-fit-content;
background-color:red;
}
<div class="parent">
<a href ="#">Link1</a>
<a href="#">Link2</a>
</div>
I see that it works for Chrome and Firefox but does not work for IE. Does anyone know what is the equivalent of -moz-center
and -moz-fit-content
in IE ?
Why not just use actual inline-block
for the container? Also, display:table
and float:left
will have the same effect.
.parent {
display: inline-block;
background: #eee;
}
.parent a {
display: block;
text-align: center;
}
<div class="parent">
<a href ="#">Link1 is long</a>
<a href="#">Link2</a>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With