html - 内联 block 在其容器的高度溢出?

标签 html css

我有这个颜色容器:

<div class="color-container">
   <div class="inline" id="red"></div>
   <div class="inline" id="green"></div>
   <div class="inline" id="yellow"> </div>
   <div class="inline" id="blue"> </div>
</div>

还有 CSS:

.color-container {
  width: 300px;
  height: 320px;
  position: relative;
  text-align: center;
  margin: auto;
 }

但是我的 child 溢出了父颜色容器的高度? children 有这样的风格:

#green {
  height: 150px;
  width: 150px;
  background-color: green;
  border-radius: 0 100% 0 0;
  border: solid #333333;
  border-width: 2px 2px 1px 1px;
}

inline如下:

.inline {
  display: inline-block;
}

我原以为它不会溢出,但这是结果: enter image description here

最佳答案

您应该根据边框最小化宽度和高度,因为边框总共为 3px(水平和垂直)。和 float:left;

.color-container {
  width: 300px;
  height: 320px;
  position: relative;
  text-align: center;
  margin: auto;
 }
.color-container > div {
  float:left;
  height: 147px;
  width: 147px;
  background-color: green;
  border-radius: 0 100% 0 0;
  border: solid #333333;
  border-width: 2px 2px 1px 1px;
}
#red {
  background-color: red;
  border-radius: 100% 0 0 0;
}
#green {
  background-color: green;
  border-radius: 0 100% 0 0;
}
#yellow {
  background-color: yellow;
  border-radius: 0 0 0 100%;
}
#blue {
  background-color: blue;
  border-radius: 0 0 100% 0;
}
.inline {
  display: inline-block;
}
<div class="color-container">
   <div class="inline" id="red"></div>
   <div class="inline" id="green"></div>
   <div class="inline" id="yellow"> </div>
   <div class="inline" id="blue"> </div>
</div>

关于html - 内联 block 在其容器的高度溢出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46308358/

相关文章:

php - 为具有多个文本列的 PDF 设置样式

html - 当我缩小网页时,为什么我的 2 个组件在 bootstrap 中相互重叠?

html - 如何使填充全宽而屏幕两侧没有任何空白?

css - 使用 CSS 调整不同大小的图像

html - 使用 CSS 的响应式表格

python - bs4 中 .find() 的正确语法是什么?

html - 设置 GitHub Pages 元素页面。页面打开但图像和 main.css 未加载

html - 视口(viewport)元标记

html - 是否可以在 Bootstrap 导航选项卡中添加图标?

javascript - 重定向到应用商店或谷歌播放