html - 如何在html中的框中制作框

标签 html css

body,
html {
  background-color: blue;
  height: 100%;
}

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}

.box {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: pink;
  height: 50%;
  width: 50%;
}

.child {
  position: absolute;
  background: grey;
  height: 10%;
  width: 10%;
}
<div class="container">
  <div class="box">
    <div class="box child"></div>
    <div class="box child"></div>
    <div class="box child"></div>
  </div>
</div>

所以我一直试图在一个盒子(盒子)中制作盒子(盒子 child ),但即使我复制并粘贴了一堆盒子 child ,它也没有让我创建多个。

这是我第一次做 html,所以如果你能像你向一个 8 岁的 child 解释一样解释,我将不胜感激。

最佳答案

position:absolute 是您的问题。这会将框定位在其容器内的 0,0(左上角),因此每个框(不指定 leftrighttopbottom 将从这个位置开始。也就是说,你所有的盒子都放在彼此的顶部。尽可能避免使用绝对位置,让内容自然下落,然后用其他值(如填充和边距)移动它.

关于html - 如何在html中的框中制作框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60200972/

相关文章:

html - 位置 : absolute; only visible when hovering over the div

javascript - img 后的段落不会展开

html - 多次使用时图像质量会下降

javascript - 使用 javascript(无 jQuery)将第一个元素之后的所有元素添加到 div

指定字体时 HTML 输入框对于数据来说太宽

jquery - First and Second touch a button,如何显示不同时间的图像?

html - 如何在 div 元素中水平居中按钮元素?

html - 表格边框半径不四舍五入或使用边框折叠会使表格的其余部分困惑

html - 收缩和居中 bootstrap 3 形式

html - 表格行内的 div 未扩展 100%