最好使用 CSS 将表格垂直居中

发布于 2024-09-11 08:51:31 字数 157 浏览 4 评论 0原文

我正在寻找如何将元素(表格)垂直居中的运气不佳。我尝试了 CSS 垂直对齐:中间;这不起作用我也尝试了 margin-top: auto;下边距:自动;这也不起作用。我还使用了表属性 valign 作为“中间”,但仍然不起作用。我正在使用 Chrome,但也在 IE 中测试了所有这些策略,结果相同。

I am looking without much luck how to center an element (a table) vertically. I tried CSS vertical-align: middle; which did not work I also tried margin-top: auto; margin-bottom: auto; which also did not work. I also used the table attribute valign as "middle" which still did not work. I am using Chrome but have tested all these strategies in IE as well with the same results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女猫性小仙女 2024-09-18 08:51:31

这里是一个页面,展示了实现此目的的技术和如何在几个不同的场景中使用它。此方法有一个问题,因为它依赖于您知道要垂直居中的元素的高度。如果您不知道这一点,那么这对您不起作用。

Here is a page which shows a technique to accomplish this and a how to use it in a couple different scenarios. This method has one issue since it relies on you knowing the height of the element you want to vertically center. If you don't know that then this will not work for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文