浮动元素下的按钮对齐

时间:2017-04-25 12:56:39

标签: html css

请参阅未对齐enter image description here

的按钮的附图

CSS和html是:

<div class="row">
<div class="col-lg-10">
    <div class="athlete-image">
        <img src="{{ url('assets/img/profile.png') }}" class="img-circle img-responsive img-center">
    </div>                      
    <div class="info-pad">
        <div class="athlete-name">
            <h4>{{ $an_athlete->name }} {{ $an_athlete->surname }}</h4>    
        </div>
        <div class="athlete-info">
            <p><i class="fa fa-phone athlete-info-icon" aria-hidden="true"></i> {{ $an_athlete->cellphone }}</p>
            <p><i class="fa fa-male athlete-info-icon" aria-hidden="true"></i> {{ $an_athlete->gender }}</p>
            <p><i class="fa fa-female athlete-info-icon" aria-hidden="true"></i> {{ $an_athlete->gender }}</p>
        </div>
        <div class="action-btns">
            <a href="{{ route('admin.edit_athlete', ['athlete' => $an_athlete->id]) }}" class="btn btn-labeled btn-info">
                <span class="btn-label"><i class="fa fa-pencil"></i></span>Edit Profile</a>
            <a href="{{ route('admin.test_athlete', ['athlete' => $an_athlete->id]) }}" class="btn btn-labeled btn-info" role="button">
                <span class="btn-label"><i class="fa fa-heartbeat"></i></span>Create New Test Day</a>
        </div>
    </div>                       
</div>

.athlete-image {
max-height:100px;
max-width:100px;
overflow:hidden;
padding-top: 10px;
padding-left: 10px;
margin-bottom: 20px;
float: left;
}

.info-pad {
 margin-left: 15px;
 float: left;
}

.athlete-name {
 margin-top: 5px;    
}

.athlete-info {
 display: inline-block;
 float: left;
}

.athlete-info > p {
 font-size: 14px;
 color: #666666;    
 float: left;
 padding-right: 12px;
 display: inline-block;    
}

.action-btns{
 padding: 15px 0px;    
}

我已尝试在操作按钮后添加<div style="clear: both;"></div>并在操作按钮css中包含float: left。没有帮助。 如果我使按钮标签更短,它可以正常工作和对齐。 问题:为什么两个蓝色按钮彼此不相邻?

2 个答案:

答案 0 :(得分:1)

您必须使用clear:both来清除浮动元素。
只需添加以下CSS即可解决此问题

.action-btns{
  padding: 15px 0px;    
  clear: both;
}

答案 1 :(得分:0)

添加明确:两者;因为.athlete-info是浮动的.action-btns按钮。

.action-btns {   
  clear: both;
}