CSS问题,下拉菜单显示空白区域

时间:2014-06-02 17:41:49

标签: html css

所以我一直在使用CSS和HTML,到目前为止我还没能解决这个问题。基本上,按钮在下拉菜单中的图像下方显示一些空白区域。我这里有代码

http://jsfiddle.net/BVN9G/

HTML

<ul id="nav" class="drop">
        <! Boton de Inicio>
        <li id="main">
        <img src="http://i.imgur.com/6PmX8Bw.png" border="0" height="50px" width="66px" style="top:3px; z-index:1;"  />
            <ul>
                <li><a id="drop1" href="mensaje_content.html" target="_self">Mensaje del presidente</a></li>
                <li><a id="drop1" href="pasos_en_verde.html" target="_self">Lo m&aacute;s destacado</a></li>
                <li><a id="drop1" href="perfil_Org.html" target="_self">Perfil de la Organizaci&oacute;n</a></li>
                <li id="seleccionada"><font color="#5AAF92">Gobierno corporativo</font></li>
                <li><a id="drop1" href="BaBF.html" target="_self">Brindando un mejor futuro</a></li>
                <li><a id="drop1">An&aacute;lisis stakeholders</a></li>
            </ul>
        </li>
        </ul>

CSS

ul#nav {margin: -2px;}
        ul.drop a { display:block; color: #058052; font-family: Verdana; font-size: 14px; text-decoration: none;}
        ul.drop, ul.drop li, ul.drop ul { list-style: none; margin: 0; padding: 0; border: 1px solid #058052; background: #fff; color: #058052;}
        ul.drop { position: relative; z-index: 597; float: left; }
        ul.drop li { float: left; line-height: 1.3em; vertical-align: middle; zoom: 1; padding: 5px 10px; }
        ul.drop li.hover, ul.drop li:hover { position: relative; z-index: 599; cursor: default; background: #058052; color: #fff; }
        ul.drop ul { visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598; width: 195px; background: #058052; }
        ul.drop ul li { float: none; }
        ul.drop ul ul { top: -2px; left: 100%; }
        ul.drop li:hover > ul { visibility: visible }
        ul.drop li a:hover{background: #058052; color: #fff;}
        ul.drop li:hover>a {background: #058052; color: #fff;}
        li#main {padding:0px; border: 0px; display: block; background:transparent; border-color:transparent; color:transparent; }

3 个答案:

答案 0 :(得分:6)

将图像的vertical-align属性设置为top:

img {
    vertical-align:top;
}

<强> jsFiddle example

或者将图像设置为display:block。

img {
    display:block;
}

<强> jsFiddle example

请注意,在这两个示例中,CSS都会定位您的所有图片,因此请使选择器更具针对您的需求。

答案 1 :(得分:3)

li#main {
padding: 0px;
border: 0px;
display: block;
background: transparent;
border-color: transparent;
color: transparent;
height: 50px;
}

添加高度将修复

答案 2 :(得分:1)

试试这个(修改后的第5行ul.drop.li)

line-height:0.3em

替换你的代码放一个:

ul#nav {margin: -2px;}
    ul.drop a { display:block; color: #058052; font-family: Verdana; font-size: 14px; text-decoration: none;}
    ul.drop, ul.drop li, ul.drop ul { list-style: none; margin: 0; padding: 0; border: 1px solid #058052; background: #fff; color: #058052;}
    ul.drop { position: relative; z-index: 597; float: left; }
    ul.drop li { float: left; line-height: 0.3em; vertical-align: middle; zoom: 1; padding: 5px 10px; }
    ul.drop li.hover, ul.drop li:hover { position: relative; z-index: 599; cursor: default; background: #058052; color: #fff; }
    ul.drop ul { visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598; width: 195px; background: #058052; }
    ul.drop ul li { float: none; }
    ul.drop ul ul { top: -2px; left: 100%; }
    ul.drop li:hover > ul { visibility: visible }
    ul.drop li a:hover{background: #058052; color: #fff;}
    ul.drop li:hover>a {background: #058052; color: #fff;}
    li#main {padding:0px; border: 0px; display: block; background:transparent; border-color:transparent; color:transparent; }