Make A List Item Clickable (HTML/CSS)

Viewed 140384

So I'm trying to make each list-item on my site clickable but I'm not sure what is the best way to do it. Please help me out.

So here is the relevant HTML:

<ul>
    <li>Backpack <a href="#" title="Buy on Amazon" target="_blank"><img src="img/basket.png" height="16" width="16" alt="Buy" class="buy" onClick="pageTracker._trackEvent('Amazon', 'School Supplies', 'Backpack');"/></a></li>
    <!-- More List Items -->
</ul>

And here is the relevant CSS:

.content ul li {
    display:block;
    list-style:none;
    padding:5px 10px 5px 15px;
}

.content li li {
    // This is for when there are sub-categories.
    border-bottom: none;
    border-top: 1px solid #f8d9d0;
    margin: 3px -10px -3px -15px;
    padding: 5px 0px 5px 30px;
}

.buy {
    float: right;
    margin-top: -2px;
}

// The next ones all deal with the shopping cart icon that appears only on hovers.

.listblock ul li img { 
    visibility: hidden;
}

.listblock ul li:hover img { 
    visibility: visible;
}

.listblock ul li ul li img { 
    visibility: hidden !important;
    margin-right: 10px;
}

.listblock ul li ul li:hover img { 
    visibility: visible !important;
    margin-right: 10px;
}

How can I make the whole list-item clickable and still have the shopping cart icon and Google Analytics Event tracking still work? Is there some jQuery magic I can use?

I've tried using display:block for the Amazon links, but that seems to mess up the image placement.

Thank you so much!

8 Answers

HTML and CSS only.

#leftsideMenu ul li {
  border-bottom: 1px dashed lightgray;
  background-color: cadetblue;
}

#leftsideMenu ul li a {
  padding: 8px 20px 8px 20px;
  color: white;
  display: block;
}

#leftsideMenu ul li a:hover {
  background-color: lightgreen;
  transition: 0.5s;
  padding-left: 30px;
  padding-right: 10px;
}
<div id="leftsideMenu">
  <ul style="list-style-type:none">
    <li><a href="#">India</a></li>
    <li><a href="#">USA</a></li>
    <li><a href="#">Russia</a></li>
    <li><a href="#">China</a></li>
    <li><a href="#">Afganistan</a></li>
    <li><a href="#">Landon</a></li>
    <li><a href="#">Scotland</a></li>
    <li><a href="#">Ireland</a></li>
  </ul>
</div>

Related