La propiedad de alineación HTML DOM TableHeader se usa para establecer o devolver la alineación horizontal del contenido dentro del encabezado de la tabla. No es compatible con HTML 5.
Sintaxis:
- Devuelve la propiedad de alineación .
TableHeaderobject.align
- Establece la propiedad de alineación .
TableHeaderObject.align = "left|right|center|justify|char"
Valores de propiedad:
- left: Establece el texto alineado a la izquierda.
- right: Coloca el texto alineado a la derecha.
- center: Establece el texto alineado al centro.
- justificar: Estira el texto del párrafo para igualar el ancho de todas las líneas.
- char: Establece el text-align a un carácter específico.
Valor devuelto: Devuelve un valor de string que representa la alineación horizontal del elemento <th>.
Ejemplo 1: El siguiente código ilustra cómo devolver la propiedad de alineación de TableHeader .
HTML
<!DOCTYPE html> <html> <head> <!-- Style to set border --> <style> table, th, td { border: 1px solid black; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <h2> DOM TableHeader align Property </h2> <table> <tr> <th id="table" style="padding:15px" align="left"> Username </th> </tr> <tr> <td>Manas Chhabra</td> </tr> </table> <br> <button onclick="clickbtn()"> Click Here! </button> <p id="paraID" style="font-size:25px;color:green"></p> <!-- Script to access th element --> <script> function clickbtn() { var tab = document.getElementById( "table").align; document.getElementById("paraID") .innerHTML = tab; } </script> </body> </html>
Producción:
Ejemplo 2: El siguiente código ilustra cómo establecer la propiedad de alineación de TableHeader .
HTML
<!DOCTYPE html> <html> <head> <!-- Style to set border --> <style> table, th, td { border: 1px solid black; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <h2> DOM TableHeader align Property </h2> <table> <tr> <th id="table" style="padding:15px" align="left"> Username </th> </tr> <tr> <td>Manas Chhabra</td> </tr> </table> <br> <button onclick="click1()"> Click Here! </button> <p id="paraID" style= "font-size:25px;color:green"> </p> </center> <!-- script to access th element --> <script> function click1() { var tab = document.getElementById( "table").align = "right"; document.getElementById("sudo") .innerHTML = tab; } </script> </body> </html>
Producción:
Navegadores compatibles:
- Google Chrome
- Firefox
- Borde de Microsoft
- Ópera
- Safari
- explorador de Internet
Publicación traducida automáticamente
Artículo escrito por ManasChhabra2 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA