2015-12-16 60 views
-2

嘿,我在集中我的網頁時遇到問題。當我嘗試只將中心左側居中時,右側延伸。這是我的頁面的外觀:居中頁面Css

screenshot

正如你可以在上部看到有一個白色的框,該框超出了我的心頁。

所以我想右側也居中。

HTML代碼:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="it_seminar.Site1" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <link href="StyleSheet1.css" rel="stylesheet" type="text/css" /> 
    <title>IT-seminar</title> 

</head> 
<body background="Images/dark-planingwood.png" > 
    <form id="form1" runat="server"> 
    <div id="center"> 
     <div id="header"> 

     </div> 
     <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 
     </asp:ContentPlaceHolder> 
    </div> 
    </form> 
</body> 
</html> 

CSS:

body { 
    text-align:center; 
} 
#center { 
    position:relative; 
    margin: 0 auto; 
    width:800px; 
    text-align:left; 
} 
#header { 
    height:50px; 
    background:#F0F0F0; 
    border:1px solid #CCC; 
    width:2000px; 
    margin:0px auto; 
} 
+0

刪除自閉合體標籤。 ''到'' –

+0

請在此處輸入您的代碼。 – KittMedia

+4

代碼圖片不是代碼。 – PeeHaa

回答

0

主體包含一個居中的div,這是800像素寬。 假設身體本身超過800像素寬,這將導致在此:

enter image description here

然後你把一個2000像素寬格,左對齊,該#center DIV中。這會出來爲

enter image description here

(或者至少嘗試,但當然得到由屏幕的邊緣切斷。)

所以,問題是,你是什麼想?

  • 如果您希望整個#header適合#center,請不要使它比#center更寬!換句話說,從它的CSS中刪除width
  • 或者,您希望儘可能多地使用#header以適應屏幕,將其從#center中取出並放入標記中。即#center結束標記</div>之後。