2011-01-22 35 views
0

這是我的CSS -實現這個用CSS和HTML

#nav { 
    position: relative; 
    background-color: #292929; 
    float: left; 
    width:960px; 
    margin-left:auto; 
    margin-right:auto; 

} 
#nav li { 
    float: left; 
    list-style: none; 

    width:auto; 

} 
#nav li a { 
    color: #e3e3e3; 
    position: relative; 
    z-index: 2; 
    float: left; 

} 
ul, li { 
    margin:0; 
    padding: 0; 

} 

#blob { 

    position: absolute; 
    top: 0; 
    z-index : 1; 
    background: #0b2b61; 


    background-repeat:repeat; 

} 

我希望把這個對象的中心。我怎麼做。我也希望背景適合頁面。我嘗試了很多,但它不起作用。

<ul id="nav"> 
     <li><a href="home.php">Home</a></li> 
</ul> 
+0

你想要列表項目在水平導航中居中?有點困惑於結果應該是什麼。 = /。 – Andrew 2011-01-22 21:23:45

回答

1

放置在中心的目標: CSS:

.Center1 
    { 
    position:relative; 
    text-align:center; 
    } 

.Center2 
{ 
position:relative; 
margin-left:auto; 
margin-right:auto; 
width:1024px; 
height:800px; 
text-align:left; 
} 

標記:

<body class="body"> 
<div class="Center1"> 
    <div class="Center2"> 
       <!-- Your content --> 

+0

不起作用... – sarthak 2011-01-22 21:27:31

0

你想放置<li> INT中心,對不對?

根據您目前的標記最簡單的方法是應用固定的width並將margin: 0 auto;添加到您的li。

該解決方案的語義是非常糟糕的,但我想你並不在乎。