当div的高度不固定时,不使用Javascript的div的垂直居中 [英] Vertical centering of div without Javascript when div's height isn't fixed

查看:114
本文介绍了当div的高度不固定时,不使用Javascript的div的垂直居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其高度不固定时

我在这里找到了 的一个想法。

I found here one idea.

我不知道是否有其他解决方案来解决这个问题。

I wonder if there are other solutions to this problem.

推荐答案

这工作:

以下链接: http:// jsbin.com/uvodop/2/edit

看看它是如何在框内垂直对齐的。身高也是不固定的。

See how it's vertically aligned within the box. Height as well isn't fixed.

希望它能回答您的问题。

Hope it answers your question.

<html>
<head>
    <title>HTML Div vertical align using CSS</title>
    <style type="text/css">
        .outerDiv {
            border: solid 1px #000000;
            width: 300px;
            padding: 5px 2px 5px 2px;
        }

        .innerDiv {
            width: 95%;
            margin: 0px auto;
            padding: 40px 0px 40px 5px;
            border: solid 1px #000000;
        }
    </style>
</head>
<body>
    <div class="outerDiv">
        <div class="innerDiv">
            This text is placed inside the next HTML div tag.<br />
            CSS style is used to vertical align the nested div and text.
        </div>
    </div>
</body>
</html>

这篇关于当div的高度不固定时,不使用Javascript的div的垂直居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆