简体   繁体   English

如何对齐导航栏,使其始终位于我的白框中间(没有填充等)?

[英]How do I align my navbar so it's permanently in the middle of my white box (without padding etc)?

This is my website. 这是我的网站。 The nav bar is causing me horrendous problems. 导航栏给我造成了可怕的问题。 Last night my friend told me it was dropping down and I just don't know how to fix it: 昨晚我的朋友告诉我它正在下降,我只是不知道如何解决它:

http://i60.tinypic.com/23iigpi.png http://i60.tinypic.com/23iigpi.png

So I removed the width and reduced the text on some buttons which is depressing for me. 因此,我删除了宽度并减少了某些按钮上的文字,这对我来说很沮丧。

Anyway, now I want my smaller nav bar to centre in the middle of my white block. 无论如何,现在我想让较小的导航栏居中于我的白色方块中间。 Does anyone know the best way? 有谁知道最好的方法?

http://www.simplypsychics.com/null/index-test.html http://www.simplypsychics.com/null/index-test.html

I have tried: 我努力了:

and modifying various positioning in the CSS but nothing seems to work. 并修改CSS中的各种位置,但似乎无济于事。

This is my CSS for the nav: 这是我的导航的CSS:

#nav {
position: absolute;
top: 98px;
left:15px;
float: left;
list-style: none;
background-image:url(../images/menubanner.png);
background-color: #f5c3fd;
border-radius:7px;
-webkit-box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.05);
-moz-box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.05);
box-shadow: 1px 3px 1px rgba(0, 0, 0, 0.05);
}
#nav li {
float: left;
}
#nav li a {
display: block;
padding: 8px 13px;
text-decoration: none;
font-weight: bold;
color: #494949;
border-right: 1px solid #fceaff;
}
#nav li a:hover {
color: #822e8e;
}
#nav .home-icon1 {
background: url(../images/icon-home.png) no-repeat center;
width: 39px;
height: 34px;
background-color: #494949;
color: #f5c3fd;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
position: relative;
border-right: 1px solid #fceaff;
float: left;
padding: 0;
list-style: none;
}
#nav .home-icon1 a:hover {
background: url(../images/icon-home.png) no-repeat center;
width: 39px;
height: 34px;
background-color: #494949;
color: #f5c3fd;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
position: relative;
border-right: 1px solid #fceaff;
float: left;
padding: 0;
list-style: none;
}
#nav .home-icon2 {
background: url(../images/icon-findapsychic.png) no-repeat left;
padding: 0px 0px 0px 15px;
}
#nav .home-icon3 {
background: url(../images/icon-psychicreadings.png) no-repeat left;
padding: 0px 0px 0px 25px;
}
#nav .home-icon4 {
background: url(../images/icon-bookareading.png) no-repeat left;
padding: 0px 0px 0px 22px;
}
#nav .home-icon5 {
background: url(../images/icon-aboutus.png) no-repeat left;
padding: 0px 0px 0px 30px;
}
#nav .home-icon6 {
background: url(../images/icon-help.png) no-repeat left;
padding: 0px 0px 0px 14px;
}

and this is my HTML: 这是我的HTML:

<div id="nav" style="margin:0 auto !important;">
<li class="home-icon1" onclick="window.location.href='http://www.simplypsychics.com/'"></li>
<li class="home-icon2"><a href="http://www.simplypsychics.com/readers/" target="_parent">FIND A PSYCHIC READER</a></li>
<li class="home-icon3"><a href="http://www.simplypsychics.com/readings/" target="_parent">PSYCHIC READINGS</a></li>
<li class="home-icon4"><a href="http://www.simplypsychics.com/book/" target="_parent">BOOK A READING</a></li>
<li class="home-icon5"><a href="http://www.simplypsychics.com/psychicreadings/" target="_parent">FIND OUT MORE</a></li>
<li class="home-icon6"><a href="http://www.simplypsychics.com/help/" target="_parent">HELP/FAQ</a></li>
</div>

Also if the nav bar looks awful for you like it did my friend please let me know! 另外,如果导航栏对您来说很糟糕,就像我的朋友那样,请告诉我! :( :(

If the nav bar is more-or-less a set width ( #nav looks to stay at 840px) then you can set left:50% and margin-left:-420px (-420 px because it's half the width of the navbar, and we want to move it towards the left). 如果导航栏设置的宽度#nav#nav看起来保持在840px),则可以设置left:50%margin-left:-420px (-420 px,因为它是导航栏宽度的一半,我们想将其向左移动)。 This should work because you've already set the navbar to be positioned absolutely. 这应该起作用,因为您已经将导航栏设置为绝对定位。

You'll have to remove this from the #nav div though: style="margin:0 auto !important;" 不过,您必须从#nav div中删除它: style="margin:0 auto !important;"

Inline style and !important is doubly bad! 内联样式和!important加倍不好!

On parent (#headerwhiteback) set: text-align: center; 在父项(#headerwhiteback)上设置:text-align:center;

Then on #nav, remove: position: absolute; 然后在#nav上,删除:position:absolute; float: left; 向左飘浮;

And add this CSS: 并添加以下CSS:

#nav {
    display: inline-block;

}
#nav::before {
    content: "";
    clear: both;
}

Also, to your liking: add margin-top: on #nav (25px seems ok) and make padding-top: on next element, #headertextbottom, much smaller (20px seems ok). 另外,根据您的喜好:在#nav上添加margin-top:(似乎可以25px),并在下一个元素上使padding-top:#headertextbottom小得多(看起来可以20px)。

This is just a quick fix for your header. 这只是标题的快速修复。 Please remember: CSS looks horrific here and looks set to be rewritten from scratch or only cause you more and more trouble. 请记住:CSS在这里看起来太恐怖了,看起来将被重新编写,否则只会给您带来越来越多的麻烦。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM