如何居中这些元素?
问题描述:
我想水平居中这些元素:如何居中这些元素?
<table width="100%" border="0">
<tr>
<td align="center" style="border-width: 0px;"><label >Filière : </label>
<select name="id_filiere" id="id_filiere" width="100px" tmt:required="true" tmt:message="">
<option value="0">-- Selectionnez --</option>
{foreach $toFilieres as $oFiliere}
<option value="{$oFiliere->id_filiere}">{$oFiliere->lib_filiere}</option>
{/foreach}
</select>
</td>
</tr>
<tr>
<td align="center" style="border-width: 0px;"><label >Session : </label>
<select name="id_session" id="id_session" width="100px" tmt:required="true" tmt:message="">
<option value="0">-- Selectionnez --</option>
</select>
</td>
</tr>
<tr>
<td align="center" style="border-width: 0px;"><label >Phase : </label>
<select name="id_phase" id="id_phase" width="100px" tmt:required="true" tmt:message="">
<option value="0">-- Selectionnez --</option>
</select>
</td>
</tr>
<tr>
<td align="center" style="border-width: 0px;">
<label >Epreuve : </label>
<select name="id_matiere" id="id_matiere" width="100px" tmt:required="true" tmt:message="">
<option value="0">-- Selectionnez --</option>
</select>
</td>
</tr>
<tr>
<td align="center" style="border-width: 0px;">
<input id="btnRech" type="button" value="Rechercher" />
<a id="Verouillage" href="#popupVerouillage"><input id="btnVerouillage" type="button" value="Verrouiller sujet" /></a>
<a id="ExporterSujet" href="#popupExporterSujet"><input id="btnExporterSujet" type="button" value="Exporter données" /></a>
</td>
</tr>
</table>
答
标签的大小不一样。所以你需要给左边一列固定的width
,并将文本对齐到右边。使用下面的CSS可以做到完美。但与此同时,如果您希望中心是分离的,那么您可以同时输入<label>
和<select>
,宽度相同。
label {display: inline-block; width: 100px; text-align: right;}
select {display: inline-block; width: 150px;}
<table width="100%" border="0">
<tr>
<td align="center" style="border-width: 0px;"><label >Filière : </label>
<select name="id_filiere" id="id_filiere" width="100px" tmt:required="true" tmt:message="">
<option value="0">-- Selectionnez --</option>
{foreach $toFilieres as $oFiliere}
<option value="{$oFiliere->id_filiere}">{$oFiliere->lib_filiere}</option>
{/foreach}
</select>
</td>
</tr>
<tr>
<td align="center" style="border-width: 0px;"><label >Session : </label>
<select name="id_session" id="id_session" width="100px" tmt:required="true" tmt:message="">
<option value="0">-- Selectionnez --</option>
</select>
</td>
</tr>
<tr>
<td align="center" style="border-width: 0px;"><label >Phase : </label>
<select name="id_phase" id="id_phase" width="100px" tmt:required="true" tmt:message="">
<option value="0">-- Selectionnez --</option>
</select>
</td>
</tr>
<tr>
<td align="center" style="border-width: 0px;">
<label >Epreuve : </label>
<select name="id_matiere" id="id_matiere" width="100px" tmt:required="true" tmt:message="">
<option value="0">-- Selectionnez --</option>
</select>
</td>
</tr>
<tr>
<td align="center" style="border-width: 0px;">
<input id="btnRech" type="button" value="Rechercher" />
<a id="Verouillage" href="#popupVerouillage"><input id="btnVerouillage" type="button" value="Verrouiller sujet" /></a>
<a id="ExporterSujet" href="#popupExporterSujet"><input id="btnExporterSujet" type="button" value="Exporter données" /></a>
</td>
</tr>
</table>
预览
将所有''
@鲍曼像我说的... :) –
毫米,是的。这就是为什么我发表评论而不是答案。 :P – jBaumann