这是我创建的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>
答案 0 :(得分:1)
如果您的元素保留宽度的50%
,则它们之间将没有空格。
其中一个div必须小于50%,而使用display: flex
和justify-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;
}
&#13;
<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>
&#13;