tags:

views:

69

answers:

3

Why is it like this?

What's the reason inside it?

+3  A: 

When you float it, you implicitly make it a block element. And unlike inline elements (a included among these), block elements can be assigned a width and height. Here's a good explanation of block vs. inline differences.

Edit: removed "have layout" as part of description of block elements, this isn't quite true...

Ben
Why you say "you implicitly make it a block element."?What's your evidence?
Csser
It's in the official CSS spec at w3.org.
DisgruntledGoat
The W3's wording on it is admittedly a little vague, but, describing the possible float properties, the spec says: "The element generates a block box that is floated to the left." Source: http://www.w3.org/TR/CSS2/visuren.html#float-position . In other words, inline element or no, it's going to be a block element once the float is applied.
Ben
+3  A: 

<a> is an inline element and flows amongst regular text. As Ben says, floating elements implicitly converts them to "block" elements.

One solution is to use the CSS style display: inline-block - the link will then work much like an image - flow inline with text, but also allow you to set a width/height.

DisgruntledGoat
+1  A: 

The premise is incorrect.

use an inline-block

<a href="" style="display:inline-block; width:100px;  background-color:Red;">abc</a>
Middletone