Foro de elhacker.net

Programación => Desarrollo Web => Mensaje iniciado por: James_JPM en 8 Noviembre 2016, 18:25 pm



Título: Duda para centrar contenido de una celda HTML
Publicado por: James_JPM en 8 Noviembre 2016, 18:25 pm
EDITO: Ya está solucionado. El fallo era el padding dentro del td.

Buenas a todos.

Pues el problema que tengo es el que comento en el título. Quiero centrar el contenido de las celdas de mi página HTML, pero cuando intento aplicar propiedades en la parte CSS como "text-align: center;" no me funciona, mientras que propiedades como la de cambiar el tipo de letra o aumentar su tamaño sí.

Aquí el código HTML y CSS, de momento aún no hice la parte lógica de la página porque me quedé estancado con esto. Que seguramente sea una tontería, pero bueno, que yo no la encuentro.  :xD
Código:
<doctype HTML>
<html>
<head>
<meta charset='utf-8'>
<title>Tarefa UD02</title>
<style>

body{

margin: 0 auto;
}

table{

padding-top: 10px;
padding-bottom: 20px;
}


h1{

margin-left: 500px;
font-family: "Tahoma", "Geneva", sans-serif;
font-size: 30px;
text-decoration: underline;
}

h2{

margin-top: 150px;
margin-left: 500px;
font-family: "Tahoma", "Geneva", sans-serif;
font-size: 30px;
text-decoration: underline;
position: absolute;
}

th{

font-family: "Tahoma", "Geneva", sans-serif;
font-size: 15px;
}

#contenedor2 th{

text-decoration: underline;
}

tr{

background-color: red;
}

td{

font-family: "Tahoma", "Geneva", sans-serif;
1font-weight: bold;
font-size: 15px;
padding-left: 50px;
}

table{

margin: 0 auto;
}

#contenedor1{

margin: 0 auto;
width: 1200px;
height: 130px;
background-color: #F5F6CE;
border: 2px solid black;
}

#contenedor2{

margin: 0 auto;
margin-top: 70px;
width: 1200px;
height: 180px;
background-color: #F5F6CE;
border: 2px solid black;

}

#contenedor2 tr{

background-color: red;
}

#caja_text{

font-family: "Tahoma", "Geneva", sans-serif;
font-size: 15px;
text-align: left;
}

</style>
</head>
<h1>DATOS PERSONAIS</h1>
<h2>DATOS ACADÉMICOS</h2>
<body>
<form name='' method='' action='' id=''>
<div id='contenedor1'>
<table>
<tr>
<th>Nome:</td>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
<th>Apelidos:</td>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
<th>NIF:</td>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
</tr>
<tr>
<th>Data Nac:</th>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
<th>Ender. postal:</th>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
<th>Localidade:</th>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
</tr>
<tr>
<th>Concello:</th>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
<th>CodPostal:</th>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
<th>Provincia:</th>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
</tr>
<tr>
<th>Teléfono fixo:</th>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
<th>Teléfono móbil:</th>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
<th>E-mail:</th>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text'></td>
</tr>
</table>
</div>
<div id='contenedor2'>
<table>
<tr>
<th><span>Acceso ó ciclo</span></th>
<th><span>Ano de inicio do ciclo</span></th>
<th><span>Grupo</span></th>
<th><span>Repetidor/a</span></th>
</tr>
<tr>
<td><input type='radio' name='check' id='caja_text'>Bacharelato</td>
<td><label for='textfield'></label>
<input type='text' name='' id='caja_text2'></td>
<td><input type='radio' name='rad_grup' id='caja_text'>&nbsp;&nbsp;1º</td>
<td><input type='radio' name='rad_rep' id='caja_text'>&nbsp;&nbsp;Si</td>
</tr>
<tr>
<td><input type='radio' name='check' id='caja_text'>Proba de acceso</td>
<td></td>
<td><input type='radio' name='rad_grup' id='caja_text'>&nbsp;&nbsp;2º</td>
<td><input type='radio' name='rad_rep' id='caja_text'>&nbsp;&nbsp;Non</td>
</tr>
<tr>
<td><input type='radio' name='check' id='caja_text'>Ciclos</td>
</tr>
<tr>
<td><input type='radio' name='check' id='caja_text'>Outros</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Gracias de antemano. :)


Título: Re: Duda para centrar contenido de una celda HTML
Publicado por: hackmastter en 14 Noviembre 2016, 04:16 am
Hola amigo...

Mmmm... No entiendo tu duda. Yo acabo de probar el text-align: center; y funciona perfectamente.

Dentro de:
Código:
#caja_text { text-align: left; }

Cambialo por:
Código:
#caja_text { text-align: center; }

Mmmm... Bueno, no sé si esa es tu duda...