动态 DIV 使用 CSS 垂直居中对齐

发布于 2024-10-04 05:48:07 字数 419 浏览 0 评论 0原文

我正在寻找 CSS 中垂直对齐的最佳方法。我发现这是一个没有很好解决的问题:vertical-align 属性与 HTML 中的属性不同。我需要一个像水平方式的 margin:auto 属性一样工作的代码。我现在使用的代码并非在所有地方都有效(例如:fadeIn 对象)。这里是:

<div style="width:200px; height:100px; background:white; display:table">
    <div style="display:table-cell; vertical-align:middle">
        <img src="image.jpg" height="20" width="100" />
    </div>
</div>

I am looking for the best way of vertical-aligning in CSS. I experience that this is a not-well-solved issue: vertical-align property is not the same as in HTML. I need a code working like the margin:auto property in horizontal way. The code I am using right now is not working everywhere (ex: fadeIn the object). Here it is:

<div style="width:200px; height:100px; background:white; display:table">
    <div style="display:table-cell; vertical-align:middle">
        <img src="image.jpg" height="20" width="100" />
    </div>
</div>

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

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

发布评论

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

评论(2

凉城凉梦凉人心 2024-10-11 05:48:07

尝试此处使用的绝对位置方法。如果您实际上发布了带有动画之类的 jsfiddle ,以便我们可以看到,那就太好了。

Try the absolute position method used here. It would be nice if you actually posted a jsfiddle with animations and whatnot so we can see.

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