tags:

views:

54

answers:

2

I'm trying to create a "cancel" link that looks like an x with a solid red circle behind it.

Here is the CSS:

.circle {
  display:inline;
  padding-left:4px;
  padding-right:4px;
  background:rgb(196,15,24);
  -moz-border-radius:10px;
  -webkit-border-radius:10px;
}

.circle a {
  font-size:10px;
  text-decoration:none;
  color:#fff;
}

This is the HTML code:

<div class='circle'>
  <a href="">x</a>
</div>

It ends up looking like this: alt text.

How do I move the x so that it is centered within the circle? Changing the margin-top or bottom doesn't seem to work...

+1  A: 

If you relatively position your a tag you can fix it:

.circle a {
  font-size:10px;
  text-decoration:none;
  color:#fff;

  position:relative; top:-2px;
}

Adjust the top value to your liking.

mVChr
Maybe padding-bottom would do the trick here too, but I know Internet Explorer is (or has been) picky about vertical paddings on inline elements (it crops stuff that extends beyond the line height).
Francis Gagné
+1  A: 

Your font must accomodate characters like É, q, X and x, etc and still be displayed over background whatever the height of the character is.

I found that using an X (or text-transform: uppercase; obviously) and font-family: monospace; was an improvement with your code, though not perfect. Solution provided by mhr is useful even with a monospace font.

Felipe Alsacreations