如何在另一个'div'中将div与'inline-block'属性对齐?

时间:2017-09-12 18:21:36

标签: html css

如何在.square内对齐#about_container

他们都应该10px位于#about_container的顶部,有或没有文字。

#about_container {
  position: absolute;
  width: 100%;
  height: 200px;
  background-color: rgba(146, 106, 106, 1);
  margin-bottom: 50px;
  overflow-x: scroll;
  white-space: nowrap;
  overflow-y: scroll;
  padding-top: 10px;
  padding-bottom: 10px;
}

.square {
  display: inline-block;
  height: 180px;
  width: 180px;
  background-color: white;
  margin-left: 5px;
  margin-right: 5px;
  border-radius: 5px;
  font-size: 10px;
  text-align: center;
  word-wrap: break-word;
}
<div id="about_container">
  <div class="filler_space"></div>
  <div class="square">
    <p>Well here hfdasjkhfidi</p>
  </div>
  <div class="square"></div>
  <div class="square"></div>
  <div class="square"></div>
  <div class="square"></div>
  <div class="filler_space"></div>
</div>

1 个答案:

答案 0 :(得分:0)

vertical-align: top添加到.square类。

如果您希望文本在到达宽度的末尾时中断,则可以在white-space: normal类上设置.square,以便它不会继承white-space: nowrap规则它的父母。

#about_container {
  position: absolute;
  width: 100%;
  height: 200px;
  background-color: rgba(146, 106, 106, 1);
  margin-bottom: 50px;
  overflow-x: scroll;
  white-space: nowrap;
  overflow-y: scroll;
  padding-top: 10px;
  padding-bottom: 10px;
}

.square {
  display: inline-block;
  height: 180px;
  width: 180px;
  background-color: white;
  margin-left: 5px;
  margin-right: 5px;
  border-radius: 5px;
  font-size: 10px;
  text-align: center;
  word-wrap: break-word;
  vertical-align: top;
  white-space: normal;
}
<div id="about_container">
  <div class="filler_space"></div>
  <div class="square">
    <p>Meow mix delivers chicken and liver. Meow mix delivers chicken and liver.</p>
  </div>
  <div class="square"></div>
  <div class="square"></div>
  <div class="square"></div>
  <div class="square"></div>
  <div class="filler_space"></div>
</div>