Perché non riesco a centrare a < td > in IE7?
-
06-07-2019 - |
Domanda
In Firefox, " C " è centrato, a causa del blurb CSS all'inizio. Perché IE7 lo giustifica a sinistra?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<style type="text/css">
td {
text-align: center;
width: 130px;
}
</style>
</head>
<body>
<div style="width: 300px; background-color: #888">
<table>
<tbody>
<tr>
<td>A</td>
<td>B</td>
</tr>
<tr>
<td colspan="2">C</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Soluzione
Ciò accade perché hai larghezza: 130px;
. Prova a impostare la larghezza solo per le celle piccole, ad esempio:
td.span {
width:auto;
}
<td colspan="2" class="span">C</td>
Vedi esempio: http://jsbin.com/etoka
Puoi anche farlo al contrario: dare una classe alle celle piccole, all'intera riga o al meglio: impostare la larghezza della < table >
.
Altri suggerimenti
usalo sempre per posizionare un oggetto al centro della tua pagina questa funzione è disponibile in tutti i browser più diffusi come IE FF Safari Chrome Opera
<center> This is my centered text</center>
per favore dammi un voto se il tuo problema è risolto
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow