【问题标题】:CSS: Positioning [closed]CSS:定位[关闭]
【发布时间】:2016-03-15 01:53:53
【问题描述】:

所以我有以下html序列:

<div class="box-content">
   <div class="box1 box"></div>
   <div class="box2 box"></div>
   <div class="box3 box"></div>
</div>

我正在尝试如下图所示显示它们:

有人知道合适的 css 吗?

【问题讨论】:

  • 去学习Bootstrap的网格系统getbootstrap.com/css/#grid。您会惊奇地发现它是一个救生员,而且它还可以响应平板电脑和移动设备。

标签: css position css-position


【解决方案1】:

您可以使用Flexbox 来做到这一点。

body, html {
  margin: 0;
  padding: 0;
}

* {
  box-sizing: border-box;
}

.box-content {
  display: flex;
  height: 100vh;
  flex-wrap: wrap;
}

.box {
  border: 3px solid black;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  background: #22B14C;
  margin: 10px;
}
.box2, .box3{
  flex: 0 0 calc(50% - 20px);
}

.box1 {
  flex: 0 0 calc(100% - 20px);
}
<div class="box-content">
   <div class="box1 box">One</div>
   <div class="box2 box">Two</div>
   <div class="box3 box">Three</div>
</div>

【讨论】:

    【解决方案2】:

    body {
      color: white;
    }
    .box-content {
      width: 700px;
      height: 210px;
      margin: 0 auto;
      background: red;
      border:10px solid red;
    }
    .box1 {
      width: 680px;
      height: 80px;
      background: green;
      padding: 10px;
     }
    .box2 {
      width: 325px;
      height: 80px;
      background: green;
      float: left;
      padding: 10px;
      margin-top: 10px;
     }
    .box3 {
      width: 325px;
      height: 80px;
      background: green;
      float: right;
      padding: 10px;
      margin-top: 10px;
     }
    <div class="box-content">
       <div class="box1 box">Box 1</div>
       <div class="box2 box">Box 2</div>
       <div class="box3 box">Box 3</div>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-18
      • 2022-01-25
      • 1970-01-01
      • 2017-02-14
      • 2016-04-21
      • 1970-01-01
      • 2017-09-06
      • 2015-12-28
      相关资源
      最近更新 更多