Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center text character ☢ vertically and horizontally within a circle (CSS)

I am trying to center this text character ☢ within a circle. (☢)

While IE 10 displays the text vertically and horizontally centered, both Chrome and Firefox render too much padding at the top.

Any ideas how to fix this? (Flexbox is not a must have)

HTML

<div class="tl-icon">
<div>☢</div>
</div>

CSS

.tl-icon {
    align-items: center;
    background: black;
    border-radius: 50%;
    color: yellow;
    display: flex;
    font-size: 3em;
    height: 3rem;
    justify-content: center;
    width: 3rem;
}

See live demo here: http://codepen.io/dash/pen/ZYePWP

like image 823
dash Avatar asked Sep 29 '22 23:09

dash


2 Answers

The problem is that the inner child is a text which screws with your height.

I added a line-height which seems to fix it a bit:

.tl-icon div{
  line-height:1px;
}

http://codepen.io/anon/pen/ZYePBZ

like image 153
ITroubs Avatar answered Oct 25 '22 03:10

ITroubs


Target that child div, set it to inline-block and change the vertical alignment:

.tl-icon div{
  display: inline-block;
  vertical-align: top;
}

CODEPEN

like image 33
jmore009 Avatar answered Oct 25 '22 02:10

jmore009