flex 属性与按钮高度混淆?

新手上路,请多包涵

我正在使用 bootstrap 并使用 flex 进行布局。

目前按钮正在占用容器的高度。文本下方有很多空间,我想删除 i ,当我向按钮添加填充时,它的大小变得不均匀。我试图通过行高调整大小,但我试图找到实际的解决方案以及我遇到这个问题的原因。

我在这里缺少任何关于 flex 的东西还是其他东西?任何帮助将不胜感激。谢谢。

 .vessel-card {
  display: flex;
  flex-direction: column;
}
.vessel-card h3 {
  margin: 0;
  padding: 20px 0;
}
.departure-card {
  display: flex;
  padding: 20px 0;
  border-top: 2px solid #888;
}
.departure-card p {
  margin-right: 10px;
}
.departure-card:last-child {
  border-bottom: 2px solid #888;
}
.departure-card .btn-explore {
  border: 1px solid #000;
  display: inline-block;
  text-transform: uppercase;
  color: #000;
  border-radius: 0;
}
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <div class="col-md-4 vessel-card">
      <a href="cienfuegos-from-havana.html" class="special-departure">
        <img src="http://placehold.it/350x150">
      </a>
      <h3>Vessel: Panorama</h3>
      <div class="departure-card">
        <p>Havana to Cienfuegos starting at $5,999</p>
        <a href="#" class="btn btn-explore">Explore</a>
      </div>
      <div class="departure-card">
        <p>Havana to Cienfuegos starting at $5,999</p>
        <a href="cienfuegos-from-havana.html" class="btn btn-explore">Explore</a>
      </div>
    </div>
  </div>
</div>

原文由 vikrantnegi 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 338
2 个回答

Flexbox make items same height as you can see here Demo , but you can use align-items to change that or in your case Demo

 .parent {
  align-items: center;
  display: flex;
}

.child {
  border: 1px solid black;
  margin: 5px;
}

.child:first-child {
  height: 100px;
}
 <div class="parent">
  <div class="child">Child</div>
  <div class="child">Child</div>
</div>

原文由 Nenad Vracar 发布,翻译遵循 CC BY-SA 3.0 许可协议

有两种可能的解决方案

1. d-flexalign-items-* 可以帮助你。

 <link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
rel="stylesheet"/>

<div class="d-flex justify-content-center align-items-center bg-info" style="height: 160px;">
  <button class="btn btn-success">align-items-* saved me :)</button>
</div>

2. NO css button div 只需包裹 span

 <link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
rel="stylesheet"/>

<div class="d-flex justify-content-around bg-info" style="height: 160px;">
  <span>
    <button class="btn btn-success">span or div saved me :)</button>
  </span>

  <button class="btn btn-danger">Aw, flex infected me ;(</button>
</div>

原文由 WasiF 发布,翻译遵循 CC BY-SA 4.0 许可协议

推荐问题