Make whole
  • as link with proper HTML
  • 前端 未结 9 2096
    忘掉有多难
    忘掉有多难 2021-02-02 13:23

    I know this has been up a lot of times before, but I couldn\'t find any solution in my specific case.

    I\'ve got a navigation bar and I want the whole

  • 相关标签:
    9条回答
    • 2021-02-02 13:35
      • Get rid of the <div>s.
      • Set the <a> tags to have display: block
      • Move the padding from the <li> to the <a>.
      • The <li>s will need to be either floated or display: inline-block

      Example: http://jsfiddle.net/8yQ57/

      0 讨论(0)
    • 2021-02-02 13:37

      I myself just had this problem.

      The answer couldn't be simpler:

      <li class="menuitem"><a href="index.php"><div class="menulink">Lnk1</div></a></li>
      Wrong:
      .menuitem {
          list-style-type:        none;
          display:                 inline;
          margin-left:            5px;
          margin-right:            5px;
          font-family:            Georgia;
          font-size:                11px;
          background-color:        #c0dbf1;
          border:                 1px solid black;
          padding:                10px 20px 10px 20px;
      }
      
      Correct
      .menuitem a {
          list-style-type:        none;
          display:                 block;
          margin-left:            5px;
          margin-right:            5px;
          font-family:            Georgia;
          font-size:                11px;
          background-color:        #c0dbf1;
          border:                 1px solid black;
          padding:                10px 20px 10px 20px;
      }
      

      in other words, you want to apply the css that the LI's had to the A element. Making sure that the A is a block line element

      0 讨论(0)
    • 2021-02-02 13:40

      a sir you use jquery ? if yes, you can try it :

      $("li").click(function(){
         $(this).find('a').click();
      });
      

      or you could use it too as css:

      li{
        position:relative;
      }
      li a {
        position:absolute;top:0px;left:0px;width:100%;height:100%;
      }
      

      Choose one ... Good luck

      0 讨论(0)
    • 2021-02-02 13:43

      You should make the a elements display:block or display:inline-block.

      0 讨论(0)
    • 2021-02-02 13:43

      Move the <a> tags so that they wrap the <li> tags. According to this answer, anchor tags must contain inline elements, and it looks like your <li>'s are inline, so this should be valid.

      0 讨论(0)
    • 2021-02-02 13:52

      Just use "display block" for link.

      ul {
        display: block;
        list-style-type: none;
      }
      
      li {
        display: inline-block; /* or block with float left */
        /* margin HERE! */
      }
      
      li a {
        display: block;
        /* padding and border HERE! */
      }
      

      Here's the example http://jsfiddle.net/TWFwA/ :)

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