Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
715 views
in Technique[技术] by (71.8m points)

html - CSS: anchor will NOT accept height

I have been pulling my hair our for over an hour on this and I just can't understand why it's not working.

HTML:

<div id="mainmenu">
    <div class="menu">
        <ul>
            <li class="page_item page-item-6"><a href="http://localhost/mysite/blog/">Blog</a></li>
            <li class="page_item page-item-4 current_page_item"><a href="http://localhost/mysite/">Front Page</a></li>
            <li class="page_item page-item-2"><a href="http://localhost/mysite/sample-page/">Sample Page</a></li>
        </ul>
    </div>
</div>

CSS:

div#mainmenu { position: absolute; top: 40px; right: 0; font-size: 77%; }
div#mainmenu div.menu ul,
div#mainmenu div.menu ul li,
div#mainmenu div.menu ul li a
{
    height: 36px;
}
div#mainmenu div.menu ul {  
    display: table;
    float: left;
    width: 700px;
    table-layout: fixed;

    position: relative;
}
div#mainmenu div.menu ul li
{
    display: table-cell;
    padding: 0 10px;
    overflow: hidden;
}
div#mainmenu div.menu ul li a
{
    width: auto;
    background: none;
    margin: 10px auto;
}

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Change div#mainmenu div.menu ul li a to this:

div#mainmenu div.menu ul li a
{
    display: block;
    width: auto;
    background: none;
    margin: 10px auto;
}

a elements are inline by default and you cannot set the height / width of inline elements.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...