html - 如何将连接在一起的两个多列 `<div>` 分开?

标签 html css

这是一个JSFiddle我创建了展示代码的外观。我将如何给予这些 <div>它们之间是否存在间隙,没有一个元素低于另一个元素?

.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;
}
<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>

最佳答案

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

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

检查这段代码:

.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;
}
<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>

关于html - 如何将连接在一起的两个多列 `<div>` 分开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50072253/

相关文章:

html - 如何为每种字体样式定义单独的字体 - CSS

java - 在jsp页面中显示下拉列表的选定值

javascript - HTML Textarea 默认文本? (喜欢布局)

html - asp.net 加载 css 失败

html - 如何为内容设置仅可滚动的 div?

javascript - 如何制作伪类:invalid apply to an input AFTER submitting a form

javascript - 在 javascript 中重新加载 div 在 div 中加载完整页面

html - Firefox 忽略表格单元格上的边框左上角半径

javascript - jQuery 菜单中的滚动条

javascript - Jquery 图像循环问题