简体   繁体   English

如何在带有溢出的div中垂直对齐

[英]How to vertical align in a div WITH overflow:hidden

i know that there is a lot of tutorials about verticaly align text inside a div, but i need to do that with "overflow:hidden", but it only works with "display: block", not with "display: table-cell". 我知道有很多关于div中垂直对齐文本的教程,但是我需要使用“ overflow:hidden”来做到这一点,但是它仅适用于“ display:block”,而不适用于“ display:table-cell” 。 Here is the html: http://melondev.com.br/twitter/ (Take a look at the long text, even with "overflow: hidden" they continue to go...) Thanks! 这是html: http : //melondev.com.br/twitter/ (看看长文本,即使出现“溢出:隐藏”,它们仍会继续出现...)谢谢!

You could just apply overflow: hidden to the cotaining element. 您可以只应用overflow: hidden到包含元素。

Strictly speaking, having an element with display:table-cell that is not inside an element with display:table-row which itself is not inside an element with display:table will frequently lead to unpredictable results and unexpected behaviour, this being one of them. 严格来说,具有display:table-cell的元素不在具有display:table-row的元素之内,而其本身不在具有display:table的元素之内通常会导致不可预测的结果和意外的行为,这就是其中之一。 Instead, you could easily have used a <table> element like this: 相反,您可以轻松地使用<table>元素,如下所示:

<table style="table-layout: fixed;">
    <tr>
        <td style="width: 100px; overflow: hidden; vertical-align: middle;">Text here</td>
    </tr>
</table>

The above works! 以上作品! You could also have rows for your note header and stuff. 您还可以为注释标题和内容添加行。 Sure, it's not pretty, but it uses things that were designed for this situation. 当然,这并不漂亮,但是它使用的是针对这种情况设计的东西。

But that aside, you have <div> elements inside a <span> - this is not good and many older browsers (and some recent) will reject it. 除此之外,您还可以 <span>包含<div>元素-这不好,而且许多较旧的浏览器(以及一些最近的浏览器)都会拒绝它。 You should never have block-level elements inside an inline-level one. 内联级别的元素中绝对不能包含块级别的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM