2013-01-01 56 views
2

我不明白爲什麼我的菜單不是居中。我嘗試了從內聯元素到頁邊距的所有內容:0 auto;調整=「中心」,我不能讓菜單居中。你可以在這裏看到它http://jeremyspence.net78.net你必須向下滾動才能看到它,只有當它通過主菜單時纔會出現。這裏是一些css居中菜單

.scrollmenu { 
    display:none; 
    position: fixed; 
    top: 0; 
    text-align:center; 
    margin: 0px auto; 
    width: 1020px; 
    z-index: 10000; 
    padding:0; 
} 
.scrollmenu li{ 
    width: 200px; 
    height: 75px; 
    overflow: hidden; 
    position: relative; 
    float:left; 
    background: #fff; 
    -webkit-box-shadow: 1px 1px 2px rgba(0,0,0,0.2); 
    -moz-box-shadow: 1px 1px 2px rgba(0,0,0,0.2); 
    box-shadow: 1px 1px 2px rgba(0,0,0,0.2); 
    margin-right: 4px; 
    -webkit-transition: all 300ms linear; 
    -moz-transition: all 300ms linear; 
    -o-transition: all 300ms linear; 
    -ms-transition: all 300ms linear; 
    transition: all 300ms linear; 
} 
.scrollmenu li:last-child{ 
    margin-right: 0px; 
} 
.scrollmenu li a{ 
    text-align: left; 
    width: 100%; 
    height: 100%; 
    display: block; 
    color: #000; 
    position: relative; 
} 
.scroll-icon{ 
    font-family: 'Symbols'; 
    font-size: 60px; 
    color: #333; 
    text-shadow: 0px 0px 1px #333; 
    line-height: 80px; 
    position: absolute; 
    width: 100%; 
    height: 50%; 
    left: 0px; 
    top: 0px; 
    text-align: center; 
} 
.scroll-home{ 
    font-size: 30px; 
    opacity: 0.8; 
    text-align: center; 
    position: absolute; 
    left: 0px; 
    width: 100%; 
    height: 50%; 
    top: 30%; 
} 
.scrollmenu li:nth-child(2):hover{ 
    background-color: #CEFECE; 
} 
.scrollmenu li:nth-child(3):hover{ 
    background-color: #CEFEFE; 
} 
.scrollmenu li:nth-child(4):hover{ 
    background-color: #CECEFE; 
} 
.scrollmenu li:last-child:hover{ 
    background-color: #FECEFE; 
} 
+0

順便說一句,我answerd你的問題讓其他人發現它有答案馬上,但你可能已經檢查了這一點: http://stackoverflow.com/questions/2005954/margin-to-center-with-position-fixed(可能重複) – Raindal

回答

3

只需添加這對您的<ul class="scrollmenu"></ul>

left: 50%; 
margin-left: -510px; 

或:

left: 0; 
right: 0; 
1

看起來像你正在一個div中心?默認情況下,<div>是一個塊元素。他們以利潤率爲中心。你很近 - 你需要使左右邊距自動調整。 margin-left:auto;margin-right:auto;。這將把它放在它的父元素中,它的寬度必須是100%(塊元素默認會擴展到父元素的最大寬度)。如果它是一個內聯元素,則可以在其父級上使用text-align:center;(父級仍然需要100%寬度),並且這樣做會起作用。

1

在您的鏈接的HTML中,看起來您需要在ul菜單上方的div中設置position:fixed。看起來你正在設置position:fixed並試圖同時居中。獲取位於固定位置的父母div,然後其子ul應該能夠通過margin-left: auto; margin-right: auto;居中。

1

你有沒有嘗試給內容div的寬度?

.content { 
position: relative; 
width: 1024px; 
margin: 0 auto; 
} 

這似乎解決了Chrome中的問題。

通過設置position: fixed;沒有封閉容器的大小,菜單使用容器的窗口邊界,然後所有的項目都向左移動......以及它們都在左側。