孩子不住在父母的内部

时间:2016-12-03 12:30:26

标签: html css css3 grid-system

小提琴:https://jsfiddle.net/uatzust3/

这是我的问题的小提琴,你会发现孩子们没有留在父div card内,我也希望div s取父母的全宽度不服用。

另外,我应该在哪里学习最佳实践?我是社区的新手。提前谢谢。

左侧div (black_container)缺少内容,但应在(content_container) div内保留根据右侧div card的宽度排列的高度。

.card {
  box-shadow: 0 25px 45px rgba(0, 0, 0, 0.30), 0 15px 15px rgba(0, 0, 0, 0.22);
  max-width: 800px;
  margin: auto;
  position: relative;
}
.black_container {
  height: inherit;
  background: #333;
  display: inline-block;
  vertical-align: top;
  padding: 3%;
  font-family: 'Nunito', sans-serif;
}
.content_container {
  display: inline-block;
  padding: 3%;
  /* position: absolute;
    top:0;
    bottom: 0; */
}
.small_bar {
  padding: 3px;
  width: 30px;
  margin: 0 auto;
  background: #e4e4e4;
  margin-top: 35px;
}
.name {
  color: #fff;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 5px;
  margin: 30px auto 5px auto;
  text-align: center;
  font-weight: 800;
}
.designation {
  font-size: 10px;
  margin: 0 auto;
}
.qrcode_container {
  float: right;
}
.qr_container {
  overflow: auto;
  width: 100%;
}
.qr_text {
  display: inline-block;
  list-style-type: none;
}
.qr_text>li {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 2.5px;
  color: #9a9a9a;
}
.bars {
  display: inline-block;
  position: relative;
  top: 10px;
}
.bars .small_bar {
  width: 15px;
  background: #777;
}
.bar {
  position: absolute;
  top: -80px;
}
.qr_code {
  display: inline-block;
  height: inherit;
  border: 1px solid #e4e4e4;
  padding: 5px;
}
.button {
  width: 150px;
  letter-spacing: 1;
  text-transform: uppercase;
  font-weight: 600;
  color: #fff;
  text-align: center;
  background: #333;
  padding: 5px 10px;
}
<div class="card">
  <div class="black_container">
    <div class="circular">
    </div>
    <p class="small_bar"></p>
    <p class="name">wow</p>
    <p class="name designation">Front-End Designer</p>
  </div>
  <div class="content_container">
    <!-- qr code container ends -->
    <div class="qr_container">
      <div class="qrcode_container">
        <ul class="qr_text">
          <li>LOREM</li>
          <li>IPSUM</li>
          <li>DPOLER</li>
        </ul>
        <div class="bars">
          <div class="small_bar bar"></div>
          <div class="small_bar"></div>
        </div>
        <div class="qr_code"></div>
      </div>
    </div>
    <!-- qr code container ends -->
    <div class="card_content">
      <p>Hello!</p>
      <p>My name is lorem</p>
      <p>I am a web designer</p>
      <p>Im stuck</span>
      </p>
      <div class="button">button</div>
    </div>
    <div class="card_footer"></div>
  </div>
</div>

3 个答案:

答案 0 :(得分:0)

如果flexbox是一个选项,这很容易:

  1. display: flex添加到您的card

  2. flex: 1添加到content-container

  3. 见下面的演示:

    &#13;
    &#13;
    .card {
      box-shadow: 0 25px 45px rgba(0, 0, 0, 0.30), 0 15px 15px rgba(0, 0, 0, 0.22);
      max-width: 800px;
      margin: auto;
      position: relative;
      display: flex;
    }
    .black_container {
      height: inherit;
      background: #333;
      display: inline-block;
      vertical-align: top;
      padding: 3%;
      font-family: 'Nunito', sans-serif;
    }
    .content_container {
      display: inline-block;
      padding: 3%;
      /* position: absolute;
        top:0;
        bottom: 0; */
      flex: 1;
    }
    .small_bar {
      padding: 3px;
      width: 30px;
      margin: 0 auto;
      background: #e4e4e4;
      margin-top: 35px;
    }
    .name {
      color: #fff;
      font-size: 14px;
      text-transform: uppercase;
      letter-spacing: 5px;
      margin: 30px auto 5px auto;
      text-align: center;
      font-weight: 800;
    }
    .designation {
      font-size: 10px;
      margin: 0 auto;
    }
    .qrcode_container {
      float: right;
    }
    .qr_container {
      overflow: auto;
      width: 100%;
    }
    .qr_text {
      display: inline-block;
      list-style-type: none;
    }
    .qr_text>li {
      font-size: 18px;
      font-weight: 600;
      letter-spacing: 2.5px;
      color: #9a9a9a;
    }
    .bars {
      display: inline-block;
      position: relative;
      top: 10px;
    }
    .bars .small_bar {
      width: 15px;
      background: #777;
    }
    .bar {
      position: absolute;
      top: -80px;
    }
    .qr_code {
      display: inline-block;
      height: inherit;
      border: 1px solid #e4e4e4;
      padding: 5px;
    }
    .button {
      width: 150px;
      letter-spacing: 1;
      text-transform: uppercase;
      font-weight: 600;
      color: #fff;
      text-align: center;
      background: #333;
      padding: 5px 10px;
    }
    &#13;
    <div class="card">
      <div class="black_container">
        <div class="circular">
        </div>
        <p class="small_bar"></p>
        <p class="name">wow</p>
        <p class="name designation">Front-End Designer</p>
      </div>
      <div class="content_container">
        <!-- qr code container ends -->
        <div class="qr_container">
          <div class="qrcode_container">
            <ul class="qr_text">
              <li>LOREM</li>
              <li>IPSUM</li>
              <li>DPOLER</li>
            </ul>
            <div class="bars">
              <div class="small_bar bar"></div>
              <div class="small_bar"></div>
            </div>
            <div class="qr_code"></div>
          </div>
        </div>
        <!-- qr code container ends -->
        <div class="card_content">
          <p>Hello!</p>
          <p>My name is lorem</p>
          <p>I am a web designer</p>
          <p>Im stuck</span>
          </p>
          <div class="button">button</div>
        </div>
        <div class="card_footer"></div>
      </div>
    </div>
    &#13;
    &#13;
    &#13;

答案 1 :(得分:0)

使用类卡体,它将内容保存在卡内。

<div class="card border-success">
    <div class="card-header border-success">
        <h3 class="card-title">Card Title</h3>      
    </div>
    <div class="card-body border-success">
        <dl>
            <dt>
                Stuff
            </dt>

            <dd>
                Stuff Details
            </dd>           
        </dl>
    </div>
</div>

答案 2 :(得分:-1)

.content_container css替换为:

.content_container {
    display: inline-block;
    padding: 3%;
    vertical-align: top;
}

您滥用了职位absolute。简而言之,absolute位置会从其他元素的流中移除元素;因此,它的高度被忽略,并且从未计入您的.card容器中。