Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make entire <li> clickable with <a> element inside without javascript [duplicate]

Tags:

Is there any way?

I have a <ul> with some <li> elements inside. It's part of a dropdown menu. Each <li> becomes a box the size of the largest <li> element in the group (the one with the most text inside it).

The problem is I want people to be able to click anywhere inside each <li> box and have the link work, instead of just where the text is. I would like a non javascript solution if possible.

Here's some sample HTML. The inner <li> elements are the ones with the links.

<li class="parent Glass" style=" float: left;">  Glass     <ul class="child" style="float: left; position: absolute; z-index: 999; display: none;">     <li style=" float: left;">                 <a href="http://example.com/path/to/somehwere.html?glass=25">Brown       (13)</a>      </li>     <li style=" float: left;">                 <a href="http://example.com/path/to/somehwere.html?glass=112">Crystal       (93)</a>      </li>     <li style=" float: left;">                 <a href="http://example.com/path/to/somehwere.html?glass=99">Gray       (1)</a>      </li>     <li style=" float: left;">                 <a href="http://example.com/path/to/somehwere.html?glass=42">Latte       (12)</a>      </li>     <li style=" float: left;">                 <a href="http://example.com/path/to/somehwere.html?glass=72">White       (15)</a>      </li>     </ul>  </li> 
like image 331
Buttle Butkus Avatar asked Feb 10 '13 21:02

Buttle Butkus


People also ask

How do I make a whole div a clickable link?

Create CSSSet the position to "absolute" for the inner <a> tag. Use the z-index property to place the link above all the other elements in the div.

How do you make a whole card clickable?

Making the whole card clickable Positioning each list item relative makes sure all positioned elements are contained in it. Create an overlay over the whole list item that links to the document works with CSS generated content. Setting a z-index of 1 makes sure this covers all elements without positioning.

How do I make a clickable element in HTML?

The most important attribute that allows one to make links in HTML is the href attribute of the <a> element. As mentioned before, the href attribute indicated the link's destination. To break the code that helps you make text clickable in HTML and understand it better, <a href=” “> helps one to specify the target.


1 Answers

You need to add display:block to your <a> tags, then you can set a width and height or padding [on the <a>], if you want to make the clickable region bigger.

like image 129
mpen Avatar answered Sep 22 '22 11:09

mpen