2012-11-11 30 views
1

iam是web開發新手,iam嘗試將整個div移動到頁面中心。但iam無法做到這一點,也沒有得到任何錯誤。 以下是html頁面的代碼。無法將整個div移動到頁面的中心

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<style> 
#chart { 
width:500px; 
height:450px; 
background-color:white; 
-moz-border-radius: 20px; 
    -webkit-border-radius: 20px; 
    -khtml-border-radius: 20px; 
    border-radius: 20px; 
    behavior: url(PIE/PIE.htc); 
} 
</style> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<title>Here goes some tilte</title> 
<meta name="DESCRIPTION" content="Determine your ring size in different countries."> 
<meta name="KEYWORDS" 
content="ring, size, USA, american, german, french, british, japanese, swiss"> 
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> 
function changeValues(which) { 
    document.countries.D1.selectedIndex = which; 
    document.countries.D2.selectedIndex = which; 
    document.countries.D3.selectedIndex = which; 
    document.countries.D4.selectedIndex = which; 
    document.countries.D5.selectedIndex = which; 
    document.countries.D6.selectedIndex = which; 
    document.countries.D7.selectedIndex = which; 
    document.countries.D8.selectedIndex = which; 
    document.countries.D9.selectedIndex = which; 
} 
// --></script> 

<link href="/style.css" rel="stylesheet" type="text/css"> 
<link href="/print.css" rel="stylesheet" type="text/css" media="print"> 

<script language="JavaScript" src="/misc_functions.js" type="text/javascript"></script> 
</head> 
<body bgcolor="pink"> 
<div align="center" id="chart" > 
<center> 
<table border="0" cellpadding="10" cellspacing="0" width="450"> 
<tr> 
<td width="470" valign="top" class="content"> 
<div align="center"> 
<span class="red"><font color="Black"><h3>Here will be having a static data on the form<h3></font></span> 
</div> 
</td> 
</tr> 
</table> 
<!-- Place main data here --> 
<script language="JavaScript" src="/browser_detection.js" type="text/javascript"></script> 
<noscript> 
<blockquote> 
<p><font size="3" color="#FF0000"><b>You do not have JavaScript enabled.</b></font><br> 
<font size="2" color="#000080">The conversions on this site require the use of JavaScript so please enable before continuing. 
For assistance in enabling JavaScript, please contact the webmaster.</font></p> 
</blockquote> 
</noscript> 
    <form method="POST" name="countries"> 
<div align="center"> 
<table border="0" style="border: 1px solid rgb(255,0,0)"> 
    <tr> 
    <td align="center" bgcolor="#DFDFDF">USA </td> 
    <td align="center" bgcolor="#D5D5FF">INDIA</td> 
    <td align="center" bgcolor="#D5D5FF">PAKISTAN</td> 
    <td align="center" bgcolor="#D5D5FF">CHINA</td> 
    </tr> 
    <tr> 
    <td align="center" bgcolor="#DFDFDF"><select name="D1" size="1" 
    onChange="changeValues(document.countries.D1.selectedIndex);"> 
     <option>&nbsp;&nbsp;---</option> 
<option>Damodar</option> 
     </select></td> 
    <td align="center" bgcolor="#D5D5FF"><select name="D2" size="1" 
    onChange="changeValues(document.countries.D2.selectedIndex);"> 
     <option>&nbsp;&nbsp;---</option> 
     <option>Damodar</option> 
     </select></td> 
    <td align="center" bgcolor="#D5D5FF"><select name="D3" size="1" 
    onChange="changeValues(document.countries.D3.selectedIndex);"> 
     <option>&nbsp;&nbsp;---</option> 
     <option>Damodar</option> 
     </select></td> 
    <td align="center" bgcolor="#D5D5FF"><select name="D4" size="1" 
    onChange="changeValues(document.countries.D4.selectedIndex);"> 
     <option>&nbsp;&nbsp;---</option> 
     <option>Damodar</option> 
    </select></td> 
    </tr> 
</table> 
</div> 
<div align="center"> 
<table border="0" style="border: 1px solid rgb(255,0,0)"> 
    <tr> 
    <td align="center" bgcolor="#DFDFDF">British</td> 
    <td align="center" bgcolor="#DFDFDF">French</td> 
    <td align="center" bgcolor="#DFDFDF">German</td> 
    <td align="center" bgcolor="#DFDFDF">Japanese</td> 
    <td align="center" bgcolor="#DFDFDF">Swiss</td> 
    </tr> 
    <tr> 
    <td align="center" bgcolor="#DFDFDF"><select name="D5" size="1" 
    onChange="changeValues(document.countries.D5.selectedIndex);"> 
     <option>&nbsp;&nbsp;---</option> 
     <option>Damodar</option> 
    </select></td> 
    <td align="center" bgcolor="#DFDFDF"><select name="D6" size="1" 
    onChange="changeValues(document.countries.D6.selectedIndex);"> 
     <option>&nbsp;&nbsp;---</option> 
     <option>Damodar</option> 
    </select></td> 
    <td align="center" bgcolor="#DFDFDF"><select name="D7" size="1" 
    onChange="changeValues(document.countries.D7.selectedIndex);"> 
     <option>&nbsp;&nbsp;---</option> 
     <option>Damodar</option> 
     </select></td> 
    <td align="center" bgcolor="#DFDFDF"><select name="D8" size="1" 
    onChange="changeValues(document.countries.D8.selectedIndex);"> 
     <option>&nbsp;&nbsp;---</option> 
     <option>Damodar</option> 
     </select></td> 
    <td align="center" bgcolor="#DFDFDF"><select name="D9" size="1" 
    onChange="changeValues(document.countries.D9.selectedIndex);"> 
     <option>&nbsp;&nbsp;---</option> 
     <option>Damodar</option> 
    </select></td> 
    </tr> 
</table> 
     </div> 
     </center> 
    </form> 
    <table> 
    <tr> 
    <td> 
    <p align="center"><font color="#800000">Here will be having a static data on the form</font></p> 
    <p><font color="#000080"><big>Here will be having a static data on the form</big></font><ol> 
     <li><font color="#004080">Here will be having a static data on the form</font></li> 
     <li><font color="#004080">Here will be having a static data on the form</font></li> 
    </ol></p> 
    </td> 
    </tr> 
<table> 
</center> 
</div> 
</div> 
</body> 
</html> 

下面IAM連接的截圖中,你可以找到curvedbox,這是留給頁面,我想,曲線箱和根據該元素中心。 請任何人可以提出該怎麼辦呢

enter image description here

+0

'ALIGN = 「中心」'和你的其他內嵌樣式已過時的對齊方式。看看一些[基本的CSS](https://developer.mozilla.org/en-US/docs/CSS),並考慮分離風格和內容。 – bookcasey

+0

什麼是所有的「IAM」而不是「我是」? – Sparky

回答

9
#chart { 
    margin: 0 auto; 
} 

使用邊緣到中心的東西。

+0

我完全按照你的建議,但它不工作 – developer

+0

坦率地說,你對不推薦的內聯樣式('align:center'等)的使用會幫助你很困難。這是一個簡單的[demo](http://jsfiddle.net/u4zEj/) - 從它學習。 '保證金:汽車'是你如何中心塊。您需要深入瞭解代碼 - 確保您的內聯樣式不覆蓋任何內容 - 並將其應用於相關元素。 – bookcasey

+0

謝謝,當我刪除內聯樣式,然後它的工作正常 – developer

1

嘗試

#chart { 
    margin: 0 auto; 
} 

<div id="chart" > //remove align  
0

你已經把一個表內的div。所以你需要做一些事情。

<table border="0" cellpadding="10" cellspacing="0" width="450"> 
<tr> 
<td width="470" valign="top" class="content"> 
<div align="center"> 
<span class="red"><font color="Black"><h3>Here will be having a static data on the form<h3></font></span> 

變化與表100% 中心TD的持有股利和寬度爲100%

<table border="0" cellpadding="10" cellspacing="0" width="100%"> 
<tr> 
<td width="100%" valign="top" class="content" style="text-align:center;"> 
<div align="center">