Make A List Item Clickable (HTML/CSS)

后端 未结 8 1903
北恋
北恋 2020-12-03 05:26

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:

相关标签:
8条回答
  • 2020-12-03 05:52

    I'm sure it is a late response, but maybe is useful for somebody else. You can put all your <li> element content into <a> tag and add the following css:

    li a { 
        display: block; 
        /* and you can use padding for additional space if needs, as a clickable area / or other styling */ 
        padding: 5px 20px; 
    }
    
    0 讨论(0)
  • 2020-12-03 05:54

    Ditch the <a href="...">. Put the onclick (all lowercase) handler on the <li> tag itself.

    0 讨论(0)
  • 2020-12-03 06:00

    The li element supports an onclick event.

    <ul>
    <li onclick="location.href = 'http://stackoverflow.com/questions/3486110/make-a-list-item-clickable-html-css';">Make A List Item Clickable</li>
    </ul>
    
    0 讨论(0)
  • 2020-12-03 06:03

    I think you could use the following HTML and CSS combo instead:

    <li>
      <a href="#">Backback</a>
    </li>
    

    Then use CSS background for the basket visibility on hover:

    .listblock ul li a {
        padding: 5px 30px 5px 10px;
        display: block;
    }
    
    .listblock ul li a:hover {
        background: transparent url('../img/basket.png') no-repeat 3px 170px;
    }
    

    Simples!

    0 讨论(0)
  • 2020-12-03 06:05

    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>

    0 讨论(0)
  • 2020-12-03 06:05

    How about putting all content inside link?

    <li><a href="#" onClick="..." ... >Backpack <img ... /></a></li>
    

    Seems like the most natural thing to try.

    0 讨论(0)
提交回复
热议问题