2011-11-04 112 views
0
<div style="text-align:center;"> 
     <select id="sponsorList"></select>&nbsp;<img alt="Loading..." src="../../Img/ajax-loader.gif" id="loader" /> 
     <span style="display:none;" id="selectedSponsorId"></span> 
     <div id="sponsorRowDetails" style="margin-left:auto; margin-right:auto;"> 
      <table> 
       <tbody> 
        <tr> 
         <td>Effective Date: </td> 
         <td><input type="text" id="startDate" /><br /></td> 
        </tr> 
        <tr> 
         <td>End Date: </td> 
         <td><input type="text" id="endDate" /></td> 
        </tr> 
       </tbody> 
      </table> 
     </div> 
    </div> 

的中央使select框是中心,但內sponsorRowDetails中心對齊以及我不能得到的一切。對齊股利

我很喜歡簡單的CSS這樣的事情。我究竟做錯了什麼?我也嘗試text-align:center;與其他股利,以及直接在第一格保持表。

+0

我有點困惑,你想要達到什麼。你想讓你桌子的元素的文字中心對齊嗎? – doctorless

+0

我只想整個表格的內部是在頁面中心對齊,整個表格本身。 – slandau

回答

0

裏面你sponsorRowDetails div

<table align="center" style="margin: 0 auto;">

0

給了<table>的寬度,然後應用margin:0 auto;而是執行此操作的表中,將圍繞該表在容器中。

0

你的問題是,一個div默認是其父母的寬度的100%。所以在100%的寬度上設置margin: 0 auto;不會做任何事情。如果你想中心它,你需要給div一個寬度,然後你可以應用margin: auto;否則設置text-align: center;sponsorRowDetails