How to make the HTML link activated by clicking on the
  • ?
  • 后端 未结 14 2000
    没有蜡笔的小新
    没有蜡笔的小新 2020-12-07 16:18

    I have the following markup,

    相关标签:
    14条回答
    • 2020-12-07 16:51
      #menu li { padding: 0px; }
      #menu li a { margin: 0px; display: block; width: 100%; height: 100%; }
      

      It may need some tweaking for IE6, but that's about how you do it.

      0 讨论(0)
    • 2020-12-07 16:52

      Use jQuery so you don't have to write inline javascript on <li> element:

      $(document).ready(function(){
          $("li > a").each(function(index, value) {
              var link = $(this).attr("href");
              $(this).parent().bind("click", function() {
                  location.href = link;
              });
          });
      }); 
      
      0 讨论(0)
    • 2020-12-07 17:02

      Anchor href link apply to li:

      #menu li a {
             display:block;
          }
      
      0 讨论(0)
    • 2020-12-07 17:05

      As Marineio said, you could use the onclick attribute of the <li> to change location.href, through javascript:

      <li onclick="location.href='http://example';"> ... </li>
      

      Alternatively, you could remove any margins or padding in the <li>, and add a large padding to the left side of the <a> to avoid text going over the bullet.

      0 讨论(0)
    • 2020-12-07 17:05

      How to make the HTML link activated by clicking on the <li> ?

      By making your link as big as your li: just move the instruction

      display: block;
      

      from li to a and you are done.

      That is:

      #menu li
      {
          /* no more display:block; on list item */
      
          list-style: none;
          background: #e8eef4 url(arrow.gif) 2% 50% no-repeat;
          border: 1px solid #b2b2b2;
          padding: 0;
          margin-top: 5px;
      }
      
      #menu li a
      {
          display:block; /* moved to link */
          font-weight: bold;
          text-decoration: none;
          line-height: 2.8em;
          padding-right:.5em;
          color: #696969;
      }
      

      Side note: you can remove "ul" from your two selectors: #menu is a sufficient indication except if you need to give weight to these two rules in order to override other instructions.

      0 讨论(0)
    • 2020-12-07 17:06

      This will make whole <li> object as a link :

      <li onclick="location.href='page.html';"  style="cursor:pointer;">...</li>
      
      0 讨论(0)
    提交回复
    热议问题