tags:

views:

71

answers:

6

In order to make all my links looks like buttons, I've done that in my CSS:

a {
  color: #06A;
  text-decoration: underline;
  margin: 10px 20px;
  padding: 10px 20px;
  /*background-color: #EEE;*/
  border: #BBB solid 1px;
}

They look fine, however, they seem to mix-up, that is they are being positioned as if they had no padding or margins.

Take a look here, if you still don't see my point: http://picasaweb.google.com/lh/photo/1yjC0oyQUbBlo_2D4RqjLZsCgnyUSAKTKup5o2EMfkM?feat=directlink

+1  A: 

Use "display: block" to make padding and margin have a effect.

Mulmoth
+1  A: 

Try styling your links with display: inline-block;.

Frédéric Hamidi
This works on all IE versions?
Isern Palaus
+4  A: 

<a> is by nature and definition an inline element, meaning that it can't be given widths, height, paddings or margins (along with a few other styles).

To change that, simply add display: block; which will turn it into a block level element enabling paddings, margins etc.

If you want something that will stay in the flow but be able to accept these styles, use display: inline-block;. This also applies to other inline elements like <p> and <span>.

Kyle Sevenoaks
`inline-block` is exactly what I needed. Thanks!
Albus Dumbledore
@Isern Paulus, and this answer - there's an easy IE hack for `inline-block` that can be applied here.
Steve
@Steve, thank you. I'll bear that in mind. I am currently looking at: http://foohack.com/2007/11/cross-browser-support-for-inline-block-styling/ It seems pretty outdated, but it's still informative. The bad thing is that I needed to use inline-block in my mobile layout, that is the one visible to mobile browsers and I have feeling it wouldn't work right. I'll test it, and see.
Albus Dumbledore
@Albus Dumbledore: Rather than relying on hacks, take a look at my answer which marks up your list as.. well, as a list. I checked it against the Opera Mini emulator (http://www.opera.com/mobile/demo/) and it worked fine. I assume the other mobile browsers would be comparable.
AgentConundrum
@AgentConundrum, thanks a lot, man! I have forgotten about the emulator.
Albus Dumbledore
+1  A: 

You may want to consider using the float style:

<a style='float:left' href='#' />

...which will let you do all the fun stuff and "help" position your anchors as a bonus.

(If you want things to stop floating, put clear:both )

Steve
Yeah, I know about `clear` and `float`, but they don't produce the result.
Albus Dumbledore
+1  A: 

The easiest solution is to set the line-height correctly (without changing display).

elusive
Didn't think of that. Still, `inline-block` seems a better solution to me.
Albus Dumbledore
@Albus Dumbledore: `inline-block` is definitely the best solution! The downside is that it requires some hacking for IE. `line-height` avoids that (i like to keep my code as clean as possible).
elusive
Thanks @elusive. It seems Imay need to use your solution as I'd like better mobile-browser compatibility.
Albus Dumbledore
+1  A: 

@snowflake's question-level comment got me thinking.

It might help you to know that there are those who believe that using a list for this sort of content is better than marking up plain anchor tags (after all, this is a list of genres, is it not?).

The code for this would look a bit like this:

HTML:

<ul class="genrelist">
   <li><a href="#fantasy">Fantasy</a></li>
   <li><a href="#childrensliterature">Children's Literature</a></li>
   <li><a href="#speculativefiction">Speculative Fiction</a></li>
   <li><a href="#absurdistfiction">Absurdist Fiction</a></li>
   <li><a href="#fiction">Fiction</a></li>
   <li><a href="#wordicantread">Word I can't read</a></li>
</ul>

CSS:

.genrelist {
  list-style-type: none;
  overflow: hidden;
}

.genrelist li {
  /*background-color: #EEE;*/
  border: #BBB solid 1px;
  display: inline;
  float: left;
  margin: 10px 20px;
  padding: 10px 20px;
}

.genrelist li a {
  color: #06A;
  text-decoration: underline;
}

The code above would display like this (full-size image):

Demonstration of inline list markup

AgentConundrum