【问题标题】:How to vertically center a floating element [duplicate]如何垂直居中浮动元素[重复]
【发布时间】:2019-11-11 04:11:33
【问题描述】:

* {
  margin: 0px;
}
.container {
  background: #ccc;
  line-height: 50px;
  verticle-algn: middle;
  clear: both;
}
.float {
  overflow: hidden;
  float: right;
}
<div class="container">
  <button class="inside">inside</button>
  <button class="float">float</button>
</div>

请检查这个例子。我希望.float元素垂直居中.container元素作为.inside元素。但是无论我触发BFC还是添加pseudo element,我都不能清除float 元素的影响。我认为保证金不是解决此问题的最佳方法。您能告诉我如何解决,谢谢您的帮助。

【问题讨论】:

  • 首先摆脱浮动并检查重复项以更好地放置元素并对齐它们

标签: css css-float


【解决方案1】:

按照您的预期尝试它的工作。

* {
margin: 0px;
}
.container{
display:flex;
justify-content: space-between;
background: #ccc;
line-height: 50px;
}
.float{
margin: 0 auto;
}
<div class="container">
<div class="inside"><button>inside</button></div>
<div class="float"><button>float</button></div>
</div>

【讨论】:

    猜你喜欢
    • 2023-01-18
    • 2014-11-10
    • 2021-01-04
    • 2014-09-18
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2012-09-15
    • 2014-08-23
    相关资源
    最近更新 更多