css - 垂直对齐两列,较短和较长的文本

标签 css vertical-alignment

这是我正在做的一个简单的 fiddle :

http://jsfiddle.net/acolombo/xxab2345/

HTML:

<div id="container">
    <div id="DivB">Just another text.</div>
    <div id="DivA">Lots and lots of text. Lots and lots of text.Lots and lots of text. Lots and lots of text. Lots and lots of text. Lots and lots of text. Lots and lots of text. Lots and lots of text. Lots and lots of text.</div>
</div>

CSS:

#container {
    overflow: hidden;
}
#DivA {
    overflow: hidden;
    background: #ccc;
}
#DivB {
    float: right;
    background: #000;
    color: #FFF;
}

我尝试了很多方法来垂直对齐较短的文本和较长的文本,以保持一切响应,但我似乎找不到有效的解决方案。

我发现的所有类似问题都使用非动态的东西,比如说固定宽度、高度、边距或其他任何东西,这些解决方案对我的问题不起作用。谢谢!

编辑:对不起,我忘了写,较短的行仍然需要像我发布的例子一样保持它的大小,较长的文本需要除此之外缩小 当它保持静止时

最佳答案

在 flexbox 之上,您可以使用 display: table;vertical-align http://jsfiddle.net/xxab2345/2/

甚至 display: inline;display: inline-block;vertical-align http://jsfiddle.net/xxab2345/3/

关于css - 垂直对齐两列,较短和较长的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41540532/

相关文章:

jquery - 当内容展开时,在 jQuery 动画期间展开 iframe

css - 在填充空间的同时在 anchor 中垂直居中文本

html - 在 div 中居中垂直列表

css - 无法获取垂直对齐的链接

html - 如何垂直对齐动态长度的文本,同时让其环绕 float 图像?

javascript - 为什么本地的 .css 文件和 .js 文件没有链接到 index.html 文件?

html - Firefox 和 IE8 中奇怪的居中问题

改变背景图片的javascript函数

CSS 特异性过滤器

html - 表 TR TD 对齐单元格固定在底部?