首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何分离连接在一起的两个多列`<div>`s?

如何分离连接在一起的两个多列`<div>`s?
EN

Stack Overflow用户
提问于 2018-04-28 10:23:58
回答 1查看 37关注 0票数 0

这是我创建的JSFiddle,展示了代码的外观。我如何才能在不让一个元素落在另一个元素之下的情况下,让这些<div>之间有一个间隙呢?

代码语言:javascript
复制
.main-content {
  width: 50%;
  float: left;
  background: #232323;
  border-radius: 50px;
  padding-top: -10px;
  height: 315px;
}

.main-content>h2 {
  color: white;
  text-align: center;
}

.ul-main>li {
  display: block;
}

.related-content {
  width: 50%;
  float: left;
}

.video {
  text-align: center;
}
代码语言:javascript
复制
<div class='main-content'>
  <h2>GTR FACTS</h2>
  <div class='main-list'>
    <ul class='ul-main'>
      <li>The GT-R is the world’s fastest accelerating production four-seater</li>
      <li>It’s the fastest four-seat production car around the Nurburgring</li>
      <li>Nissan GT-R engines are hand built by race engineers</li>
      <li>The Nissan GT-R has near 50:50 weight distribution</li>
      <li>
      </li>
    </ul>
  </div>
</div>

<div class='related-content'>
  <div class='video'>
    <iframe width="560" height="315" src="https://www.youtube.com/embed/PAjD4GFi3Ko" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  </div>
</div>

EN

回答 1

Stack Overflow用户

发布于 2018-04-28 12:38:40

如果您的元素保留了宽度的50%,则它们之间将没有空格。

其中一个div必须小于50%,并且结合使用display: flexjustify-content: space-between将使元素彼此分开。

检查以下代码:

代码语言:javascript
复制
.container {
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;
}

.main-content {
  width: 45%;
  background: #232323;
  border-radius: 50px;
  padding-top: -10px;
  height: 315px;
}

.main-content>h2 {
  color: white;
  text-align: center;
}

.ul-main>li {
  display: block;
}

.related-content {
  width: 50%;
  float: left;
}

.video {
  text-align: center;
}
代码语言:javascript
复制
<div class="container">
  <div class='main-content'>
    <h2>GTR FACTS</h2>
    <div class='main-list'>
      <ul class='ul-main'>
        <li>The GT-R is the world’s fastest accelerating production four-seater</li>
        <li>It’s the fastest four-seat production car around the Nurburgring</li>
        <li>Nissan GT-R engines are hand built by race engineers</li>
        <li>The Nissan GT-R has near 50:50 weight distribution</li>
        <li>
        </li>
      </ul>
    </div>
  </div>

  <div class='related-content'>
    <div class='video'>
      <iframe width="560" height="315" src="https://www.youtube.com/embed/PAjD4GFi3Ko" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
    </div>
  </div>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50072253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档