css - 为什么 CSS text-align:center; 不行?
问题描述
这是代码
html {
font-family: 'Noto Sans KR', sans-serif;
}
h1 {
text-align: center;
}
img {
display: block;
margin: auto;
}
p {
font-size: 16px;
line-height: 2;
letter-spacing: 1px;
}
<h1>웹 프로그래밍 기초</h1>
<img src="images/CB9A982F-A812-486E-A9E6-30E6ACFA916D.jpeg" alt="HTML5">
<h2>2.2 CSS </h2>
<h3>글꼴과 텍스트 </h3>
<P> 글꼴과 텍스트 스타일을 바꿔봅시다</P>
我将其保存在 Visual Studio 中。但预览不应用 css 文本(如文本对齐、高度、字母间距 ..)
请帮帮我
解决方案
该text-align: center
样式在您的代码片段中的 h1 上正常工作,如果您想text-align: center
在所有元素上应用 ,您可以为所有元素使用父容器元素并将text-align: center
样式添加到其中。您可以在下面看到结果。
希望这可以帮助你:)
<html>
<body>
<style>
html {
font-family: 'Noto Sans KR', sans-serif;
}
h1 {
text-align: center;
width: 100%;
}
img {
display: block;
margin: auto;
}
p {
font-size: 16px;
line-height: 2;
letter-spacing: 1px;
}
#container {
text-align: center;
}
</style>
<div id="container">
<h1>웹 프로그래밍 기초</h1>
<img src="images/CB9A982F-A812-486E-A9E6-30E6ACFA916D.jpeg" alt="HTML5">
<h2>2.2 CSS </h2>
<h3>글꼴과 텍스트 </h3>
<P> 글꼴과 텍스트 스타일을 바꿔봅시다</P>
</div>
</body>
</html>
推荐阅读
- javascript - 创建第一个窗口时 chrome.windows.onCreated.addListener() 未运行
- java - MongoDB无法更新Java中的嵌套数组
- adfs - 角-oauth2-oidc CORS ADFS
- excel - Workbooks.Open 没有使用提供的密码,而是向用户请求密码
- javascript - 检测是否安装了 WhatsApp
- node-red - 节点红色 - 如何使用按钮停止 Bash 节点
- r - 如何在 r 中使用 ggplot2 包进行绘图
- here-api - 航点航向仅适用于第一个航点
- python - 如何强制 Pandas“read_csv”函数保留空白值
- flutter - Flutter 有多个 floatingActionButtons