0

我想在另一个父容器中对齐七个 div,除了第一个和最后一个之外,它们都应该具有相同的高度(与父容器一样)和宽度。

我尝试过这样的事情:

HTML

<div id="weatherBar">
  <div class="arrow"></div>
  <div class="table-wrapper">
    <div>1</div>
  </div>
  <div class="table-wrapper">
    <div>2</div>
  </div>
  <div class="table-wrapper">
    <div>3</div>
  </div>
  <div class="table-wrapper">
    <div>4</div>
  </div>
  <div class="table-wrapper">
    <div>5</div>
  </div>
  <div class="arrow"></div>
</div>

CSS

div#weatherBar {
  position: relative;
  width: 60vw;
  max-width: 60vw;
  height: 10vh;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgb(255, 255, 255);
  overflow: hidden;
  margin-top: 10vh;
}

div#weatherBar div.table-wrapper {
  min-height: 10vh;
  max-height: 10vh;
  min-width: 10vw;
  max-width: 10vw;
  border: solid 0.5px blue;
  float: left;
  overflow: hidden;
}

div#weatherBar div.arrow {
  min-height: 10vh;
  max-height: 10vh;
  min-width: 5vw;
  max-width: 5vw;
  float: left;
  overflow: hidden;
  background-color: red;
}

但是发生的事情是最后一个 div 没有出现(我附上了一张图片),我不知道为什么。你能帮帮我吗?

先感谢您!:-)

附图

4

1 回答 1

1

默认情况下border,of 元素不包含在width元素box-sizingcontent-box

将其更改为border-box使边框包含width使用中:

* {
  box-sizing: border-box;
}

请参阅下面的演示:

* {
  box-sizing: border-box;
}
div#weatherBar {
  position: relative;
  width: 60vw;
  max-width: 60vw;
  height: 10vh;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgb(255, 255, 255);
  overflow: hidden;
  margin-top: 10vh;
}

div#weatherBar div.table-wrapper {
  min-height: 10vh;
  max-height: 10vh;
  min-width: 10vw;
  max-width: 10vw;
  border: solid 0.5px blue;
  float: left;
  overflow: hidden;
}

div#weatherBar div.arrow {
  min-height: 10vh;
  max-height: 10vh;
  min-width: 5vw;
  max-width: 5vw;
  float: left;
  overflow: hidden;
  background-color: red;
}
<div id="weatherBar">
  <div class="arrow"></div>
  <div class="table-wrapper">
    <div>1</div>
  </div>
  <div class="table-wrapper">
    <div>2</div>
  </div>
  <div class="table-wrapper">
    <div>3</div>
  </div>
  <div class="table-wrapper">
    <div>4</div>
  </div>
  <div class="table-wrapper">
    <div>5</div>
  </div>
  <div class="arrow"></div>
</div>

于 2017-09-16T17:51:08.473 回答