Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an <a> tag the size of it's parent <li> tag for larger clickable region?

Tags:

html

css

I would like to do this so that the clickable region on the tag is size of the LI.

My html looks like:

<li>  <a href="#">Link</a> </li> 
like image 730
Alexa Green Avatar asked Aug 10 '11 23:08

Alexa Green


People also ask

How do you increase the size of a tag?

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size. HTML5 do not support the <font> tag, so the CSS style is used to add font size.

How do you make a clickable area?

The HTML <area> tag defines a clickable area (or hotspot) inside of an image map. You can associate a hyperlink with this clickable area. This tag must be within a <map> tag. This tag is also commonly referred to as the <area> element.


2 Answers

As others have said

li a { display: block; } 

should achieve what you're after. But you must also remove any padding from the <li> and set it on the <a> instead. For example:

li { padding: 0; }   li a { display: block; padding: 1em; } 
like image 158
Ola Tuvesson Avatar answered Sep 28 '22 07:09

Ola Tuvesson


In CSS:

li a {      display: block; } 

Of course, you'll want to make your selector more specific than that.

<ul>     <li class="myClass">         <a href="#">Link</a>     </li> </ul>  li.myClass a {     display: block;     background-color: #fdd; /* Demo only */ } 

http://jsfiddle.net/userdude/jmj2k/

like image 43
Jared Farrish Avatar answered Sep 28 '22 07:09

Jared Farrish