html - CSS 在其他 div 下移动 div

标签 html css

我的地铁仪表板中的一些 div 元素有问题。 我的代码示例在下面的代码片段中。

有什么方法可以移动 2 和 3 下的 4 和 5 来填充这个空房间。

.tile-group-4x2 {
   width: 216px;
   height: 108px;
}

.tile-1x1 {
     margin: 2px 2px 2px 2px;
     height: 50px;
     width: 50px;
     background: #67D4FF;
     float: left;
}
   
.tile-2x2 {
     margin: 2px 2px 2px 2px;
     height: 104px;
     width: 104px;
     background: #67D4FF;
     float: left;
}
<div class="tile-group-4x2">
    <div class="tile-2x2">1</div>
    <div class="tile-1x1">2</div>
    <div class="tile-1x1">3</div>
    <div class="tile-1x1">4</div>
    <div class="tile-1x1">5</div>
</div>
<p>
Is there any way to move tile 4 and 5 under 2 and 3 to fill this empty room.
</p>
<div class="tile-group-4x2">
    <div class="tile-1x1">2</div>
    <div class="tile-1x1">3</div>
    <div class="tile-2x2">1</div>
    <div class="tile-1x1">4</div>
    <div class="tile-1x1">5</div>
</div>

最佳答案

是的,这确实是可能的。因此,对于类 tile-2x2,我添加了类 rightleftrightfloat:rightleft float:left。因此,只需在 HTML 中添加 left 或 right,就​​可以了。

.tile-group-4x2 {
   width: 216px;
   height: 108px;
}

.tile-1x1 {
     margin: 2px 2px 2px 2px;
     height: 50px;
     width: 50px;
     background: #67D4FF;
     float: left;
}
   
.tile-2x2 {
     margin: 2px 2px 2px 2px;
     height: 104px;
     width: 104px;
     background: #67D4FF;
     float: left;
}
.left{
  float:left;
}
.right{
  float:right;
}
<div class="tile-group-4x2">
    <div class="tile-2x2 left">1</div>
    <div class="tile-1x1">2</div>
    <div class="tile-1x1">3</div>
    <div class="tile-1x1">4</div>
    <div class="tile-1x1">5</div>
</div>
<p>
Is there any way to move tile 4 and 5 under 2 and 3 to fill this empty room.
</p>
<div class="tile-group-4x2">
    <div class="tile-1x1">2</div>
    <div class="tile-1x1">3</div>
    <div class="tile-2x2 right">1</div>
    <div class="tile-1x1">4</div>
    <div class="tile-1x1">5</div>
</div>

关于html - CSS 在其他 div 下移动 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44818661/

相关文章:

php - 我的网站无法在 IE 中打开

javascript - HTML/Javascript : URL Redirect from Selected field

php - 使用多个文本框中的单个值到 php 的 sql 查询中?

javascript - 缩放 Canvas 以便 base64 toDataURL() 也被缩放

jquery - 条形图插件 - 使每个条形图都可点击(每个条形图都有不同的链接)

html - 图像重叠在 div 上

HTML/CSS 元素位置

jquery - 检查 div 的列表项,如果没有内容则添加类

css - 传递一个空的 LESS 参数以使用默认值?

javascript - IE10 - 悬停使图像本身闪烁