【发布时间】:2021-07-13 13:31:04
【问题描述】:
我遇到了以下问题。假设我在 .html 文件正文中有类似的内容:
html,
body {
width: 99%;
height: 99%;
margin: 0px;
overflow: hidden;
}
#container1 {
display: flex;
gap: 2%;
width: 90%;
height: 10%;
border: 1px black solid;
}
.box {
border: 1px black solid;
background-color: yellow;
width: 100%;
}
.box p {
text-align: center;
}
<body>
<div id="container1">
<div class="box">
<p>Text 1</p>
</div>
<div class="box">
<p>Text 2</p>
</div>
</div>
</body>
我觉得奇怪的事情如下:
- 黄色框的大小保持不变,直到我更改其中的“p”标签的字体。
- 如果我将“p”标签的边距设置为
margin: 0;,文本会卡在黄色框的顶部。为什么会这样?
如何在不改变其父容器大小的情况下增加字体大小?以及如何使自定义的“p”标签在其父 div 内完美居中?
【问题讨论】:
-
你确定你的身高是 10% 吗?