Menu
CoddyTech

文本对齐

Coddy 如何使用 CSS 居中 div 或文本 课程的第 7 课,共 9 课。

现在来居中对齐一些文本吧!

水平居中文本的一种方法是使用 text-align 属性。

.parent {
	text-align: center;
}

上面的代码会将父元素中的所有文本水平居中对齐。

challenge icon

挑战

简单

使用 text align 将文本在父级 div 中居中对齐。

亲手试试

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="styles.css">
</head>
    <body>
        <div class="parent">
            <p class="text">
                This is some text
            </p>
        </div>
    </body>
</html>

如何使用 CSS 居中 div 或文本中的所有课

自己练习: Web 在线编辑器