2012-10-22 402 views
1

我做了一個下拉菜單CSS和誠實想不通爲什麼它變得縮進...CSS下拉菜單錯誤

下面是截圖:

如果你看到它是所有右對齊不管我怎麼設置寬度.. :(

這裏是CSS:

(包括所有的CSS,但菜單是:#mainMenu

@charset "UTF-8"; 
/* CSS Document */ 

/* Background styling of all forms (should set is here) */ 

form#payment { 
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 13px; 
    background-color:#f7fca3; 
    padding: 10px; 
} 

form { 
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 13px; 
    background-color:#d6f5df; 
    padding: 10px; 
} 

/*styling for text inputs and password of homepage */ 

input[type="text"]#profile, textarea#profile, input[type="password"]#profile { 

    font-family: Arial, Helvetica, sans-serif; 
    font-size: 13px; 
    margin-bottom: 5px; 
    display: block; 
    padding: 4px; 
    border: solid 1px #35b459; 
    width:365px; 
} 

input[type="text"], textarea, input[type="password"]#inputArea { 

    font-family: Arial, Helvetica, sans-serif; 
    font-size: 13px; 
    margin-bottom: 5px; 
    display: block; 
    padding: 4px; 
    border: solid 1px #35b459; 
    width:300px; 
} 

p { 
    font-family:Arial, Helvetica, sans-serif; 
    color:#231f20; 
} 

h1 { 
    font-family:Arial, Helvetica, sans-serif; 
    color:#231f20; 
} 

h2 { 
    font-family:Arial, Helvetica, sans-serif; 
    color:#231f20; 
} 

h3 { 
    font-family:Arial, Helvetica, sans-serif; 
    color:#231f20; 
} 

/* Split homepage in two */ 

#span1 { 
    width: 330px; float: right; 
} 

#span2 { 
    width: 390px; float: left; 
} 

/* Homepage note */ 
#note { 
    border-style:dashed;border-color:red; 
} 

/* Registration button link style */ 

.regbutton a:hover { 
    color:#ff; 
    text-decoration:none; 
} 
.regbutton a { 
    color:#ff; 
    text-decoration:none; 
} 

.regbutton a:visited{ 
    color:#ff; 
    text-decoration:none; 

} 

div#steps { 
     background-color:#f7fca3; 
} 

.regbutton 
{ 
    position:absolute; 
    color:#ff; 
    background:#E76600; 
    font-family:Arial, Helvetica, sans-serif; 
    padding:6px; 
    text-align:center; 
    left:550px; 
    bottom:30px; 
} 
.header{ 
    position:relative; 
    width:650px; 
    align:center; 
    height:200px; 
} 
.logo{ 
    position:absolute; 
    align:left; 
    left:30px; 
    top:50px 
} 
.menu{ 
    position:relative; 
    align:center; 
    top:150px; 
} 
.content{ 
    width:800px; 
    position:relative; 
    align:center; 

} 
#holder{ 
    width:100%; 
} 
.homecontent{ 
    position:relative; 
    width:700px; 
    top:20px; 
    height:500px; 
} 

a>div { display: none; } 
a:hover>div { display: block; } 

a span {display: none;} 
a:hover span#hovImg { 
    position: relative; 
    right: 0px; 
    bottom: 0px;  
    display: block; 
} 

#mainMenu, 
#mainMenu ul { 
    list-style: none; 
} 
#mainMenu { 
    float: left; 
} 
#mainMenu > li { 
    float: left; 
} 
#mainMenu li a { 
display: block; 
    height: 2em; 
    line-height: 2em; 
    padding: 0 1.5em; 
    text-decoration: none; 
} 
#mainMenu ul { 
    position: absolute; 
    display: none; 
z-index: 999; 
} 
#mainMenu ul li a { 
    width: 80px; 
} 
#mainMenu li:hover ul { 
    display: block; 
} 

/* Main menu 
--*/ 
#mainMenu { 
    font-family: Arial; 
    font-size: 12px; 
    background: #2f8be8; 
} 
#mainMenu > li > a { 
    color: #fff; 
    font-weight: bold; 
} 
#mainMenu > li:hover > a { 
    background: #f09d28; 
    color: #000; 
} 

/* Submenu 
--*/ 
#mainMenu ul { 
    background: #f09d28; 
} 
#mainMenu ul li a { 
    color: #000; 
} 
#mainMenu ul li:hover a { 
    background: #ffc97c; 
} 
+0

如果現有的答案不幫助,然後創建一個[的jsfiddle(http://jsfiddle.net),這樣的人可以確切地看到你是如何實現你的菜單 –

回答

1

ul元素都在默認情況下,幾乎所有的瀏覽器左填充。創建JS小提琴(http://www.jsfiddle.net)在這裏會很有幫助。但請嘗試設置

#mainMenu ul{ 
    padding: 0; 
    margin: 0; 
} 
1

這是可能是因爲這一點,你正在使用CSS速記:

padding: 0 1.5em; /* Top-Bottom(0), Left-Right(1.5em) */ 

#mainMenu li a { 
    display: block; 
    height: 2em; 
    line-height: 2em; 
    padding: 0 1.5em; <------ Here 
    text-decoration: none; 
} 
1

首先,是什麼瀏覽器,你看它在?我還建議使用螢火蟲或某種 加載項,這可以幫助您查看框方法,因爲您可以看到這是否是導致邊緣,填充等問題的原因。和邊界問題。我想看看你的html文件,我可以更有效地幫助你解決問題。我也認爲這是一個填充問題,但...

嘗試:

#mainMenu li a { 
display: block; 
    height: 2em; 
    line-height: 2em; 
    padding-right:.2em; /* <-- */ 
    text-decoration: none; 
}