Make whole
  • as link with proper HTML
  • 2019-03-13 01:03发布

    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 <li>'s to be "linked" or "clickable" if you will. Now only the <a> (and the <div>'s I've fiddled with) is "clickable".

    I've tried the li a {display: inner-block; height: 100%; width: 100%} method but the results where just horrible.

    The source can be found here: http://jsfiddle.net/prplxr/BrcZK/

    HTML

    <!DOCTYPE html>
    <html>
        <head>
            <title>asdf</title>
        </head>
        <body>
            <div id="wrapper">
                <div id="menu">
                    <div id="innermenu">    
                        <ul id="menulist">       
                            <li class="menuitem"><a href="index.php"><div class="menulink">Lnk1</div></a></li>
                            <li class="menuitem"><a href="index.php"><div class="menulink">Lnk2</div></a></li>
                            <li class="menuitem"><a href="index.php"><div class="menulink">Lnk3</div></a></li>
                            <li class="menuitem"><a href="index.php"><div class="menulink">Lnk4</div></a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </body>
    </html>
    

    Do anyone have a neat solution to this?

    Thank you in advance!

    9条回答
    干净又极端
    2楼-- · 2019-03-13 02:02

    Just format the a directly instead of the li with your styles.

    I have alterd your fiddle http://jsfiddle.net/BrcZK/1/

    查看更多
    仙女界的扛把子
    3楼-- · 2019-03-13 02:04

    I think you may have meant inline-block, not inner-block:

    li a {display: inline-block; height: 100%; width: 100%; }
    

    Also, inline-block has its own set of problem with older IE browsers, and probably won't react how you'd expect.

    查看更多
    4楼-- · 2019-03-13 02:05

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

    查看更多
    登录 后发表回答