Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

width for <a> tag in html

Tags:

html

Is it possible to set some width to the <a> tag in html ? If yes what is the way, if no is there any work around ??

like image 957
Anand Sunderraman Avatar asked Jan 20 '10 07:01

Anand Sunderraman


People also ask

How do you give a tag a width in HTML?

You can redefine it as a block element and then set width to it: a{display:block;width:400px} .

What is width tag?

The width attribute on an <img> tag sets the width of the image. The width is specified in pixels -- without the 'px' unit.

What does width 100% do in HTML?

If you set the width to 100% on the body element you will have a full page width. This is essentially equivalent to not setting a width value and allowing the default. If you want to use the body element as a smaller container and let the HTML element fill the page, you could set a max-width value on the body.

What is the width of HTML page?

It is a reliable standard that works on most devices down to a 1024 pixel display width including space for scroll bars and such.


3 Answers

You can redefine it as a block element and then set width to it: a{display:block;width:400px}.

EDIT: However, in this case it will start on a new line and the next piece of text will also be in a new line. What solves the problem, is inline-block display mode, but this again has problems with older versions of IE and FF (see here: http://caniuse.com/#search=inline-block)

like image 119
naivists Avatar answered Oct 16 '22 01:10

naivists


The css width property does not affect inline elements such as <a> or <span>. In order to use block-level properties like width, you'll have to declare your element as a block-level element, using display:block:

<a style="display:block;width:200px">Your link</a>
like image 42
zombat Avatar answered Oct 16 '22 02:10

zombat


If You didn't Like display:block or display:inline-block You Can Use The Padding

like image 24
Med Avatar answered Oct 16 '22 00:10

Med