Home > Article > Web Front-end > How to Make Navigation Bar List Items Fully Clickable?
Making Navigation Bar List Items Fully Clickable
In a typical horizontal navigation bar created using an unordered list, clicking anywhere on a list item will most likely only trigger the action if the cursor is within the text of the link itself. To extend the clickable area to the entire list item, modify the HTML and CSS as follows:
CSS:
<code class="css">#nav li a { display: inline-block; padding: 25px 10px; }</code>
By removing the padding from the 'li' elements and adding it to the anchor tags, the clickable area is now extended to fill the entire width and height of the list item.
HTML:
<code class="html"><div id="nav"> <img src="/images/renderedicon.png" alt="Icon" height="57" width="57" /> <ul> <li><a href="#">One1</a></li> <li><a href="#">Two</a></li> <li><a href="#">Three</a></li> <li><a href="#">Four</a></li> </ul> </div></code>
Now, users can click anywhere within the list items to activate the corresponding links, providing a more user-friendly navigation bar.
The above is the detailed content of How to Make Navigation Bar List Items Fully Clickable?. For more information, please follow other related articles on the PHP Chinese website!