CSS: Width of a link

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

CSS: Width of a link

Post by JKM »

I'm a bit stuck here with my CSS.

#blabla a {
width: 150px;
}

<div id="blabla">
<a href="#">fgdfg</a>
</div>

But the link won't be 150px wide. I've tried span, p, tt and so on, but it won't help. The link is inside a list, but I've got other styling for the list, so that won't work.
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: CSS: Width of a link

Post by mintedjo »

Hi
I'm not sure if this is considered bad code or anything but last night I used:

Code: Select all

a{display: block; width: 100px;}
To set the width of a link.
Seems to work for me.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: CSS: Width of a link

Post by pickle »

An <a> element is inline. As a result, you can't set it's width. Setting it to display as a block element (such as ~JKM suggested) or floating it will allow you to set it's width.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply