html - 如何布局 3 个 div,使一个在 div 旁边,另一个在下面?

标签 html css

假设有 3 个矩形 {1, 2, 3} 我希望矩形 1 位于左侧,矩形 2 位于矩形 1 下方,矩形 3 位于矩形 1 旁边。

.rect1{
   width: 20px;
   height: 20px;
   float: left;
}
.rect2{
   width: 20px;
   height: 20px;
}
.rect3{
   width: 40px;
   height: 40px;
   float: left;
}

<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>

我试过这个方法,但是矩形 3 漂浮在矩形 2 旁边而不是矩形 1 旁边。

最佳答案

让我们检查一下我的代码

<!DOCTYPE html>
<html>
<head>
<style>
body {
    background-color: lightblue;
}
.rect1{
   width: 20px;
   height: 20px;
   float: none;
   border:1px solid black;
}
.rect2{
   width: 20px;
   height: 20px;
   border:1px solid white;
   float:left;
}
.rect3{
   width: 40px;
   height: 40px;
   float: left;
   border:1px solid red;
   margin-top: -22px;
}
</style>
</head>
<body>

<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>

</body>
</html>

关于html - 如何布局 3 个 div,使一个在 div 旁边,另一个在下面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40479223/

相关文章:

javascript - 为什么此网页只能在 Internet Explorer 中运行?

javascript - 如何使搜索栏中的微弱单词在您单击/键入时消失?

java - 网站和 iPhone 原型(prototype)

javascript - 如何在页面更改时保持子菜单打开

php - 在 PHP/CSS 中动态创建的网格仅在 Android Firefox 浏览器中看起来不对?

asp.net - 将两个元素对齐在同一行

php - 错误 "End tag fieldset seen, but there were open elements.”

html - 哪些文件是我应该上传到主机的文件

javascript - 为什么 Facebook 不合并它的 CSS/JS 文件?

html - 如何在同一个地方的所有div上制作图像