如何在开始时删除此导航栏中的空白区域

时间:2014-05-18 04:45:55

标签: html css navbar

嗨,我只是想知道如何摆脱导航栏中的空间,非常感谢帮助。 这是jsfiddle示例:http://jsfiddle.net/Kmum7/ 这就是我在图像中的含义:http://imgur.com/Gmrok9T

这是代码:

<html>
<head>
<style>
* {
margin: 0px;
padding: 0px;
}
ul#navmenu, ul.sub1, ul.sub2 {
list-style-type: none;
font-size: 9pt;
}
 ul#navmenu li {
    width: 203px;
    text-align: center;
    position: relative;
    margin-right: -2px;
    display:inline-block;
}
#navmenu ul {
display: inline-block;
list-style-type: none;
white-space:nowrap;
}
#page1 {
text-align: center;
}
ul#navmenu a {
text-decoration: none;
display: block;
width: 203px;
height: 30px;
line-height: 25px;
background-color: #2E2E2E;
border: 1px solid #777777;
border-top: 2px solid #777777;
color: white;
font-family: Arial, sans-serif;
font-weight: bold;
font-face: Arial;
float: left;
text-align: center;
white-space: nowrap;

}
ul#navmenu .sub1 a {
margin-top: 0px;
}
ul#navmenu .sub2 a {
margin-left: 0px;
}
ul#navmenu li:hover > a {
background-color: grey;
}
ul#navmenu li:hover a:hover {
background-color: red;
}
ul#navmenu ul.sub1 {
display: none;
position: absolute;
top: 30px;
left: 0px;
}
ul#navmenu ul.sub2 {
display: none;
position: absolute;
top: 66px;
left: 203px;
}
ul#navmenu li:hover .sub1 {
display: block;
}
ul#navmenu .sub1 li:hover .sub2 {
display: block;
}
.darrow {
font-size: 10pt;
position: absolute;
top: 8px;
right: 20px;
}
#navmenu {
display: inline-block;
text-align: center;
list-style-type: none;
margin: 0px auto;
padding: 0px;
position: relative;
white-space: nowrap;

}
.rarrow {
font-size: 11pt;
position: absolute;
top: 73px;
right: 20px;
}
ul#navmenu {
width:100% !important;
}
#page1 .link1 {
color: grey;
border-top: 2px solid red;
border-left: 0px solid red;
}
#page2 .link2 {
color: grey;
border-top: 2px solid red;
border-left: 0px solid red;
}
#page3 .link3 {
color: grey;
border-top: 2px solid red;
border-left: 0px solid red;
}
.container {
width: 100%;
min-width: 1024px;
max-width: 1440px;
height: 1000px;
margin: 0px auto;
white-space: nowrap;
}
#box2 {
height: 1000px;
width: 1024px;
background-color: #FFFE8E;
align: center;
margin: 0px auto;
}
#boxinbox1 {
width: 100%;

background-color: #E51837;
}

ul#navmenu li ul li
{

display:block;

}
}

</style>

</head>
<body bgcolor="#E51837"><div id="box2"><div id="page1"><div id="boxinbox1">            .    <img src="Logo1.gif"  height="200px"><br><img src="text.gif" height="100px"></div>    .    <ul id="navmenu"><li><a href="dropdown1.html" class="link1">Home</a>
                </li>
                <li><a href="dropdown2.html" class="link2">hyperlink 2</a>               .     <font color="white">
<span class="darrow">&#9660;</font>
                    </span>
                    <ul class="sub1">
                        <li><a href="#">hyperlink 2.1</a>
                        </li>
                        <li><a href="#">hyperlink 2.2</a>
                        </li>
                        <li><a href="#">hyperlink 2.3</a>
                        </li>
                    </ul>
                </li>
                <li><a href="#">hyperlink 3</a>
                </li>
                <li><a href="#">hyperlink 4</a><span class="darrow">                   .    <font color="white">&#9660;               

 </font></span> 
                    <ul class="sub1">
                        <li><a href="#">hyperlink 4.1</a>
                        </li>
                        <li><a href="#">hyperlink 4.2</a>
                        </li>
                        <li><a href="#">hyperlink 4.3</a><span class="rarrow">
<font color="white">&#9654;</font></span>

                            <ul class="sub2">
                                <li><a href="#">hyperlink 4.3.1</a>
                                </li>
                                <li><a href="#">hyperlink 4.3.2</a>
                                </li>
                                <li>
<a href="dropdown3.html" class="link3">hyperlink 4.3.3</a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li><a href="#">hyperlink 5</a>
                </li>
            </ul>
        </div>
    </div>

</body>

</html>

非常感谢您的帮助!! :)

2 个答案:

答案 0 :(得分:1)

更改css以便显示你的navmanu li:阻止并向左浮动,同时为navmenu li li添加一个新的css类,它是内联块...

以下是代码:

 ul#navmenu li {
        width: 203px;
        text-align: center;
        position: relative;
        margin-right: -2px;
        display:block;
    float:left;
    }
ul#nav menu li li { display:inline-block;}

并更新了小提琴:http://jsfiddle.net/Kmum7/2/

答案 1 :(得分:-1)

我对上一个答案有点担心,因为它使用-Xpx页边距,如果字体发生变化,那么这还不够。我建议将li设置为向左浮动并通过使用带有text-align的内联块来定位其父级ul,或者只是使用带有边距的ul块和定位。克里斯·科伊尔(Chris Coyier)给出了一个相当广泛的列表,列出了你可以对付它的方法。

http://css-tricks.com/fighting-the-space-between-inline-block-elements/