views:

150

answers:

2

I'm using CSS3 border-radius to create circular buttons on this site:

http://hexpreview.com/

However, due to font rendering differences between Mac and Windows (not between browsers), the centering of the button's text within its bounding circle is inconsistent. Buttons render properly in all CSS3 capable browsers in Windows, but not in OS X or Linux.

Here is some simpler code that somewhat reproduces the problem:

<html>
<head>
<title>Rounded Buttons Example</title>
<style type='text/css'>
    div {padding:1em; margin:1em}
    a {text-decoration:none; color:#000;}
    #help_link, #add_link {
        display:block;
        height: 1.4em;
        width: 1.4em;
        text-align:center;
        line-height: 1.4;
        font-size:1.5em;
        padding:0;
        border:.1em solid #000;
        -moz-border-radius:.8em;
        -webkit-border-radius:.8em;
        border-radius:.8em;
    }

    #help_link:hover, #add_link:hover {
        border-width:.15em;
        margin:-.05em;
        -moz-border-radius:.85em;
        -webkit-border-radius:.85em;
        border-radius:.85em;
    }

</style>
</head>
<body>
<div>
    <a id='help_link' href='#'>?</a>
</div>
<div>
    <a id='add_link' href='#'>+</a>
</div>
</body>
</html>

I've been struggling with this for awhile, and it's starting to get messy. If this were a problem related to the CSS3 specification, I would probably let it go, but it seems to me that this is a cross-browser font issue (centering doesn't work in square buttons either). Any ideas?

EDIT

I'd like to clarify that I want the buttons to be in the exact center of the circular border. The main problem is vertical centering due to font heights being different in OS X and Windows even when line-height and font-size are specified. I am ok with a solution that involves manual positioning of the character within the button, but I've tried and manual centering on one OS is adversely affecting the others.

A: 

uh,

div {text-align: center;}

?

I have to be missing something here...

Alternatively, you could wrap your <a> tags in <p> tags and set text-align: center on the <p> tag.

EDIT

Upon further review of your page, it appears you're trying to center something that is absolutely positioned. This is difficult. Make sure you're not declaring your <a> tag as display:block and you can center it because <a> tags are inline by default.

EDIT 2

Upon further FURTHER review, all you need to do is set your #help rule to left: 50% and get rid of your right rule. That will center it just fine even while absolutely positioned :)

Jason
I think you're on the right track. Center the text on the `div`, not the `a` tag, like he currently is.
Kyle Trauberman
I'll try this, but it doesn't affect the vertical positioning. I'm fine with manually setting margins so that things look centered, but I haven't figured out a way to do this that displays the same on Windows, OS X, and Linux.EDIT -- Applying text-align:center to the containing divs does not have any effect.
vamin
how would you like the items to be vertically positioned? all you mentioned was centering...
Jason
Centered vertically and horizontally. If you look at the site in Windows, you will see what I mean. On the Mac, the question mark is too high in Firefox and the + is too low in Chrome.
vamin
ps i'm on a PC so i'd have no way to recreate your mac issues. maybe you should not spend 90% of your time worrying about what less than 8% of users see :)
Jason
i'm not sure exactly what you mean... your textbox sits right in the middle of your page... how could you vertically and horizontally center 3 elements? only 1 will be able to sit in the exact middle of the page, unless you want to layer them w/z-indexes
Jason
I'm not trying to center the buttons relative to the window. I'm trying to center the text inside them relative to the circular border. The '+' button looks really funny if the '+' is not exactly in the middle of the circle. Also, 45% of my visitors use OS X :)
vamin
ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.......... i thought you were trying to center the buttons themselves on the page... hrm... well i guess i can't help you here because they look fine to me... :\ good luck!
Jason
Thanks for trying!
vamin
ps... why not just use image sprites? it's not like "?" and "+" are going to be useful to someone who sees your page sans CSS anyways...
Jason
If you're not averse to javascript, and you really don't want to use an image, you could try using javascript. Absolute positioning using javascript could get you exactly what you want at the cost of some performance. Maintenance shouldn't be a big problem if you make it as something like a jquery plugin that works on elements marked with a certain css class.
jthg
+1  A: 

I found the problem. The font in the original page is declared as "Helvetica, sans-serif". Windows doesn't have Helvetica, so it's rendering in Arial. All the Mac browsers are rendering in Helvetica, hence the rendering issues. Changing to "Arial, sans-serif" fixes the problem.

vamin