css - 从另一个 DIV block 的一侧对齐 DIV block 的列

标签 css xhtml


我想以这种方式对齐 div block :

+-----+------+
|first|second|
|     |      |
+     +------+
|     |third |
|     |      |
+-----+------+

But the following code allign it in other manner:

<html>
    <head>
        <style>
            .common
            {
                border: 1px solid black;
                float: left;
            }

            #first
            {
                background: red;
                height: 100px;
                width: 50px;
            }

            #second
            {
                background: green;
                height: 50px;
                width: 50px;
            }

            #third
            {
                background: yellow;
                height: 50px;
                width: 50px;
            }
        </style>
    </head>
    <body>
        <div class="common" id="first">first</div>
        <div class="common" id="second">second</div>
        <div class="common" id="third">third</div>
    </body>
</html>

我不会使用绝对定位。
还有其他方法吗?

谢谢你提前。

最佳答案

您可以将 second 和 third 包装在容器 div 中,然后 float 容器和 first。

#first {
    float: left;
}

#container {
    float: left;
}

...

<div id="first></div>
<div id="container">
    <div id="second"></div>
    <div id="third"></div>
</div>

关于css - 从另一个 DIV block 的一侧对齐 DIV block 的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4287853/

相关文章:

html - Logo 图像可以响应但在 div 中不起作用

html - 指定 &lt;script&gt; 类型的顺序

jquery - 网站上的图像高度错误

jquery - 如何使用循环简化此代码

css - 是否可以在 xHTML strict 1.0 中使用 CSS 渲染空的 <div style ="width:50%"> </div> 而无需以像素为单位设置宽度和高度?

html - WordPress 麻烦

css - 2 个背景拉伸(stretch) 1 个背景

javascript - 如何在 HTML 中为样式使用变量

html - 将文字转换为纯文本(X)HTML的最简单方法或最佳工具

css - 父级 <ul> 覆盖其子级样式