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>
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With