2017-09-14 102 views
0

Demo如何避免重叠元素

enter image description here

我注意到一些时间元素重叠我不知道why.i已删除的利润从顶部元素(p标签),所以也没有办法,这是保证金collapse.so它究竟是什么?

我可以通过添加display:inline-block来解决这个问题,但有没有更好的方法可以避免这种情况?

.ui-btn { 
 
    border: 2px solid #ffffff; 
 
    border-radius: 30px; 
 
    background-color: #18aff4; 
 
    font-weight: bold; 
 
    text-align: center; 
 
    font-size: 18px; 
 
    color: white; 
 
    padding: 18px; 
 
} 
 

 
p { 
 
    margin: 0; 
 
    padding: 0; 
 
}
<div class="text"> 
 
    <p ">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It 
 
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 

 
    <a class="ui-btn ">Sign up</a> 
 
</div>

+0

使用'显示:直列block'是*如何*可以解决的......不知道为什么你要避免... – kukkuz

回答

2

您可以添加到display: inline-block;.ui-btn后显示。

<style type="text/css"> 
 
.ui-btn { 
 
    border: 2px solid #ffffff; 
 
    border-radius: 30px; 
 
    background-color: #18aff4; 
 
    font-weight: bold; 
 
    text-align: center; 
 
    font-size: 18px; 
 
    color: white; 
 
    padding: 18px; 
 
    display: inline-block; 
 
} 
 
p{ 
 
    margin: 0; 
 
    padding:0; 
 
} 
 
</style> 
 

 
<div class="text"> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It 
 
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 

 
    <a class="ui-btn">sign up</a> 
 
</div>

0

.ui-btn { 
 
    border: 2px solid #ffffff; 
 
    border-radius: 30px; 
 
    background-color: #18aff4; 
 
    font-weight: bold; 
 
    text-align: center; 
 
    font-size: 18px; 
 
    color: white; 
 
    padding: 18px; 
 
} 
 
p{ 
 
    margin:0; 
 
    padding:0; 
 
    margin-bottom:40px; 
 
}
<div class="text"> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It 
 
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 

 
    <a class="ui-btn">sign up</a> 
 
</div>

<a>标签填充没有算作一个空间。所以添加一个p{margin-bottom:40px;}到你的<p>会在它之间产生差距。

0

默认情况下,锚标签是内联标签赋予float:left;在CSS

.ui-btn { 
    border: 2px solid #ffffff; 
    border-radius: 30px; 
    background-color: #18aff4; 
    font-weight: bold; 
    text-align: center; 
    font-size: 18px; 
    color: white; 
    padding: 18px; 
    float: left; 
} 
2

你可以使用任何margin-bottomfloatinline-block</br>工作过。

.ui-btn { 
 
    border: 2px solid #ffffff; 
 
    border-radius: 30px; 
 
    background-color: #18aff4; 
 
    font-weight: bold; 
 
    text-align: center; 
 
    font-size: 18px; 
 
    color: white; 
 
    padding: 18px; 
 
} 
 

 
p { 
 
    margin: 0; 
 
    padding: 0; 
 
}
<div class="text"> 
 
    <p ">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It 
 
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 
</br> 
 
    <a class="ui-btn ">Sign up</a> 
 
</div>