底部文本对齐或菜单
我有一个菜单,有 90x50 的矩形框。有些有单行文本,其他有多行文本
问题:如何使用纯 css 将其垂直对齐到底部,请不要破解
I have a menu the have rectangular boxes 90x50. Some have single line text, other have multiline text
question : How to VERTICALLY align it to the bottom with pure css no hack please
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CSS 中的垂直对齐并不像您直观地期望的那么容易。到目前为止,简单的属性
vertical-align:bottom
仅适用于表格单元格。这是一个很好的资源,解释了如何(不)在 CSS 中垂直对齐:理解垂直对齐,或“如何(不)垂直居中内容”。简而言之:以下内容适用于真正的网络浏览器:
但因此不适用于 MSIE。您希望使父元素相对并将文本包装在绝对定位的元素中,然后将其放在底部。这是一个复制、粘贴和运行的示例。
Vertical aligninment in CSS isn't that easy as you'd intuitively expect. As far the straightforward property
vertical-align: bottom
works in table cells only. Here's an excellent resource which explains how (not) to vertical align in CSS: Understanding vertical-align, or "How (Not) To Vertically Center Content".In a nut: the following works in real webbrowsers:
But thus not in MSIE. You'd like to make the parent element relative and wrap the text in an absolutely positioned element and then put it to bottom. Here's a copy'n'paste'n'runnable example.
我认为
vertical-align
属性可以满足您的需求。否则,也许你可以进一步澄清你的问题?编辑:您可以通过使用带有值“table-cell”的
display
属性来强制任何其他元素类似表格单元格的行为。我不太确定这是否可以很好地与vertical-align
属性配合使用,但也许您可以在它的基础上进行构建。如果我没记错的话,需要一个额外的中间元素。I think the
vertical-align
property does what you want. Otherwise, perhaps you can clarify your problem further?Edit: You can force table-cell-like behaviour for any other element by using the
display
property with the value 'table-cell'. I am not perfectly sure if this works with well with thevertical-align
property, but perhaps you can build on it. If I remember correctly, an additional intermediate element was required.