【问题标题】:CSS - List item not starting from the top of unordered listCSS - 列表项不是从无序列表的顶部开始
【发布时间】:2012-03-04 00:35:28
【问题描述】:

全部,

我正在尝试构建一个顶级菜单。出于某种原因,li 元素不是从 ul 的顶部开始的,顶部似乎还有一个小边距。请解释一下。

jsfiddle:http://jsfiddle.net/K26TN/

HTML 代码:

    <div id="menu_bars">
    <div id="main_bar">
        <ul>
            <li id="overview_tab" class="maintabs"><a  id="text_overview_tab">Overview</a></li><li id="collar_tab" class="maintabs"><a id="text_collar_tab">Collar/ Neckline</a></li><li class="maintabs" id="body_tab"><a  id="text_body_tab" >Body</a></li><li id="sleeves_tab" class="maintabs"><a id="text_sleeves_tab" >Sleeves</a></li>
        </ul>
    </div>
      </div>

CSS 代码:

html {
height: 100%;
}

body#container {
position: relative;
width: 100%
min-width: 1280px;
height: 100%;
min-height: 700px;
background-color: rgba(255,255,255,0.8);
margin: 0 auto;
}

    #menu_bars {
    position: relative;
    width: 90%;
    height: 20%;
    margin: 0 auto;
}
        #main_bar {
        float: left;
        width: 78%;
        height: 100%;
    }
    #main_bar ul {
        float: left;
        width: 100%;
        height: 100%;
        border-radius: 6px;             
        -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.2);
        -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.2);
        box-shadow: 0 1px 3px rgba(0,0,0,0.2);      
    }
        .maintabs {
            display: inline-block;
            width: 25%;
            height: 100%;
            list-style-type: none;
            cursor: pointer;
            background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(255,255,255)), color-stop(100%,rgb(237,237,237))); /* Chrome,Safari4+ */
            background: -webkit-linear-gradient(top, rgb(255,255,255) 0%,rgb(237,237,237) 100%); /* Chrome10+,Safari5.1+ */
            background: linear-gradient(top, rgb(255,255,255) 0%,rgb(237,237,237) 100%); /* W3C */
        }
            .maintabs:first-child {
                border-top-left-radius: 6px;
                border-bottom-left-radius: 6px;                 }
            .maintabs:last-child {
                border-top-right-radius: 6px;
                border-bottom-right-radius: 6px;        
            }
            .maintabs a {
                display: block;
                height: 100%;
                color: rgb(125,125,125);
                line-height: 100%;
                font-size: 0.8em;
                text-decoration: none;
                text-align: center;
                text-shadow: 0px 1px 2px rgba(150,150,150,0.4);
                -moz-transition: all 0.3s ease-in;
                -webkit-transition: all 0.3s ease-in;
                -o-transition: all 0.3s ease-in;
                transition: all 0.3s ease-in;
            }
            #overview_tab a{
                color: rgb(142,101,143);
                text-shadow: 0px 1px 1px rgba(248,248,248,1);
            }
                .maintabs a:hover {
                    color: rgb(153,112,154);
                    text-shadow: 1px 1px 0 rgba(255,255,255,0.95);
                }

【问题讨论】:

    标签: css margin html-lists


    【解决方案1】:

    您的&lt;li&gt; 元素设置为display: inline-block,但它们的vertical-align 属性默认为baseline。在你的 CSS 中指定:

    #main_bar li {vertical-align: top}
    

    【讨论】:

    • 谢谢,我不知道关于 li 的项目。非常感谢 Twisol。
    • 我也没有!打开 Chrome 的 Inspector(或 Firebug,如果你喜欢的话)确实很有帮助,尤其是使用选中“显示继承”的“计算样式”窗格。
    • 很好的提示,我自己偏向于萤火虫,应该浏览一下标签。为小费干杯。
    猜你喜欢
    • 2018-05-07
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多