0

再次呼吁你们的帮助。。

不知道这里发生了什么,我的导航翻转没有正确对齐,我检查了我的测量结果,从我看到的情况来看并非如此。我正在使用 Margin:0 auto 将导航对齐到页面中心;我想知道这是否是问题所在?

我创建了一个 Fiddle http://jsfiddle.net/ca9rv/来理解我在说什么(不知道为什么底部有一条蓝线 - 在本地查看我的 html 页面时不显示) .

<ul id="navigation">
    <li id="home"><a href="index.html">Home</a></li>
    <li id="promise"><a href="Our Promise">Our Promise</a></li>
    <li id="restaurants"><a href="Our Restaurants">Resume</a></li>
    <li id="contact"><a href="#">Contact</a></li>
</ul>

#navigation {
    background:url(http://img33.imageshack.us/img33/7388/navigationq.png) no-repeat;
    width: 940px;
    height: 50px;
    margin: 0 auto;
    padding: 0;
    margin-bottom:20px;
}

#navigation li, #navigation a {
    height: 50px;
    display: block;
}

#navigation li {
    float: left;
    list-style: none;
    display: inline;
    text-indent: -9999em;
}

#home { width: 103px; }
#promise { width: 176px; }
#restaurants { width: 206px; }
#contact { width: 151px; }

#home a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") 0px -50px no-repeat; }
#promise a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") -103px -50px no-repeat; }
#restaurants a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") -277px -50px no-repeat; }
#contact a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") -482px -50px no-repeat; }
4

3 回答 3

2

改变你的 position valuewidth

像这样

#home { width: 88px; }
#promise { width: 147px; }
#restaurants { width: 176px; }
#contact { width: 128px; }

#home a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") 0px -42px no-repeat; }
#promise a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") -91px -42px no-repeat; }
#restaurants a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") -236px -42px no-repeat; }
#contact a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") -411px -42px no-repeat; }

演示

于 2013-05-02T09:35:31.810 回答
0

首先我认为你做错了。1. 停止使用背景图片,因为您希望它可以缩放。2. 快速查看一下 CSS,你的宽度都错了。为所有元素添加边框,您将看到正在发生的事情。3.那里有蓝色边框,因为菜单上的高度高于背景图像。

于 2013-05-02T09:39:08.283 回答
0

提琴手

<style>

#navigation {
    background:url(http://img33.imageshack.us/img33/7388/navigationq.png) no-repeat;
    width: 940px;
    height: 42px;
    margin: 0 auto;
    padding: 0;
    margin-bottom:20px;
}

#navigation li, #navigation a {
    height: 50px;
    display: block;
}

#navigation li {
    float: left;
    list-style: none;
    display: inline;
    text-indent: -9999em;
}

#home { width: 87px; }
#promise { width: 149px; }
#restaurants { width: 175px; }
#contact { width: 130px; }

#home a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") 0px -42px no-repeat; }
#promise a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") -91px -42px no-repeat; }
#restaurants a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") -82px -42px no-repeat; }
#contact a:hover { background:url("http://img33.imageshack.us/img33/7388/navigationq.png") -409px -42px no-repeat; }
</style>
<ul id="navigation">
    <li id="home"><a href="index.html">Home</a></li>
    <li id="promise"><a href="Our Promise">Our Promise</a></li>
    <li id="restaurants"><a href="Our Restaurants">Resume</a></li>
    <li id="contact"><a href="#">Contact</a></li>
</ul>
于 2013-05-02T09:51:32.970 回答