HTML DOM propiedad Estilo textAlign
Definición y Uso
TextAlign conjuntos de propiedades o vuelve al bloque a nivel de elementos de la alineación horizontal chino.
gramática
Configuración de las propiedades TextAlign:
Object.style.textAlign="left|right|center|justify|inherit"
Volver propiedades TextAlign:
Object.style.textAlign
值 | 描述 |
---|---|
left | 默认。把文本排列到左边。 |
right | 把文本排列到右边。 |
center | 把文本排列到中间。 |
justify | 根据 textJustify 属性对齐文本。 |
inherit | textAlign 属性的值从父元素继承。 |
Soporte para el navegador
Todos los principales navegadores soportan la propiedad textAlign.
Nota: Internet Explorer 7 y versiones anteriores no son compatibles con el valor "heredar".IE8 sólo proporciona! DOCTYPE apoyado "hereda". apoyo IE9 "hereda".
Ejemplos
Ejemplos
Alinear p elementos de texto:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.textAlign="center";
}
</script>
</head>
<body>
<p id="p1">这是一些文本。</p>
<br>
<button type="button" onclick="displayResult()">对齐文本</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.textAlign="center";
}
</script>
</head>
<body>
<p id="p1">这是一些文本。</p>
<br>
<button type="button" onclick="displayResult()">对齐文本</button>
</body>
</html>
Trate »
Objetos de estilo