Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to create a consistent ?-mark-inside-circle in CSS

Tags:

html

css

I'm trying to create a question-mark-inside-a-circle glyph using CSS. It should look like © basically.

Here's what I have so far.

a::before
{
    content: '?';
    font-size: 60%;
    font-family: sans-serif;
    vertical-align: middle;
    font-weight: bold;
    text-align: center;
    display: inline-block;
    width: 1.8ex;
    height: 1.8ex;
    border-radius: 1ex;
    color: blue;
    background: white;
    border: thin solid blue;
}

It's not bad on firefox but the positioning of the question mark inside the circle is off-centre on Chrome (and I don't have IE to test but I'm assuming the worst).

I don't understand much about the nuances of fonts. Can this approach be made to work cross-platform or should I give up and use an image? I'm doing it this way to keep it scaled with the font.

UPDATE: Tweaking the settings as suggested so far is providing improvements only in select circumstances. There always seems to be some font sizes for which there is more than a rounding error (more than 1 pixel that is) of off-centreness either horizontally or vertically. The goal is to fit the border to the question mark, not fit the border to the square box which contains the question mark, as I suspect is happening.

like image 785
spraff Avatar asked Jan 08 '14 12:01

spraff


People also ask

How do I style a circle in CSS?

To create a circle we can set the border-radius on the element. This will create curved corners on the element. If we set it to 50% it will create a circle. If you set a different width and height we will get an oval instead.

How do I make a Div A Perfect circle?

So if you want perfect circles what you have to do is to first have a square div, it has to be a square, then you go to borders and select the radius to 50%. That should make your div into a perfect circle.


1 Answers

Looks like you're missing line-height:1; Add that and it gets significantly better.

Personally I think it looks best with font-size:50%, but that's my opinion.

Updated Fiddle

like image 199
Niet the Dark Absol Avatar answered Nov 15 '22 21:11

Niet the Dark Absol