我创造了一个Bootstrap 4手风琴。我在按钮标题中有两个div。一个浮子向右移动另一个浮子。右边的是一张图片,左边的是标题和副标题。
除非我希望左边的div与右边的div相同,并且两个标题垂直对齐,否则一切都很好。
当我乱用css试图完成上述操作时,我不断在手风琴中打破其他东西。我在绳子尽头。我创造了一个小提琴,并希望有人能够提供帮助。
我在这里创建了一个小提琴:>> Fiddle<<
<div class="accordion" id="page-accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link collapsed" style="width:100%;" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
<div class="left">
<h5 class="card-title">OCTOBER 2018</h5>
<h6 class="card-subtitle mb-2">TODAY IS THE DAY</h6>
</div>
<div class="right">
<img src="pic.png" width="209px" height="119">
</div>
<div class="clear"></div>
</button>
</h5>
</div>
<div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#page-accordion">
<div class="card-body">
<p class="card-text">DETAILS COMING SOON</p>
<a href="#" class="btn btn-danger">Click here for details</a>
</div>
</div>
</div>
</div>
答案 0 :(得分:3)
您可以使用display: flex
使容器中的每个项目具有相同的高度。我还必须对容器h5
做一个小改动。显示flex是使用float
的一个很好的选择(这可能非常棘手)。
<!doctype html>
<html lang="en">
<head>
<!-- before all other stylesheets -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
</head>
<body>
<!-- ACCORDION -->
<div class="accordion" id="page-accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link collapsed" style="width:100%;" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
<h5 class="card-title">OCTOBER 2018</h5>
<h6 class="card-subtitle mb-2">TODAY IS THE DAY</h6>
</button>
</h5>
<div>
<img src="pic.png" width="209px" height="119">
</div>
</div>
<div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#page-accordion">
<div class="card-body">
<p class="card-text">DETAILS COMING SOON</p>
<a href="#" class="btn btn-danger">Click here for details</a>
</div>
</div>
</div>
</div>
</body>
</html>