【问题标题】:Vertical center multiple lines [duplicate]垂直居中多行[重复]
【发布时间】:2016-06-01 15:49:32
【问题描述】:

我需要将li 的内容垂直居中,所以我所做的是lineheight,它可以工作,但问题是当我有多行时,这种技术不再有效,我can't modify@ 987654324@,因为这是教授给出的约束。所以我真的用完了解决方案。

这是HTML 和Css

    li
    {
    
        
    	list-style-type:none; 
    	border-bottom: 1px solid #e0e0e0;
    	height: 55px;
    	display: inline-block;
        vertical-align: middle;
        width: 100%;
        line-height: 55px;
    
    }
    ul
    {
    	list-style : none;
    	 
    }
<ul>
    	<li>
             The 2015–16 UEFA Champions League was the 61st season of Europe's premier club football tournament organised by UEFA, and the 24th season since it was renamed from the European Champion Clubs' Cup to the UEFA Champions League
          
       </li>
  
    </ul>

【问题讨论】:

  • 垂直对齐方式?
  • 是垂直对齐
  • 您必须使用其他 4 或 5 种技术中的一种来垂直居中您的内容。关于 SO 的许多问题都很好地涵盖了它们。

标签: html css


【解决方案1】:

.parent {
  display: table;
  height:  260px;
  width:   180px;
  padding: 10px;
  border:  2px solid darkgray;
}
.parent li {
  border:1px solid blue;
  display:        flex;
  vertical-align: middle;
  padding:8px;
}
<ul class="parent">
  <li>Something about Footbal</li>
  <li>Something about Footbal</li>
  <li>Something about Footbal</li>
</ul>

子元素的位置与其父元素的display属性有关。如果父级将拥有display:table,则子级将拥有display:table-cell 和vertical-align:middle。

我们有更多示例here 和here

【讨论】:

  • 所以只需复制粘贴您在另一个问题中看到的答案?
  • 重复是一切学习之母 :)
  • 一件事是重复,另一件事是复制粘贴代码。
  • 啊,现在我明白你的意思是什么了。对不起,我现在编辑答案
  • 它正在工作,但现在我的 li 彼此相邻
猜你喜欢
  • 2018-10-07
  • 2017-08-16
  • 2019-06-28
  • 2012-05-11
  • 2017-06-15
  • 2018-10-29
  • 2018-04-29
  • 2013-03-29
  • 1970-01-01
相关资源
最近更新 更多