【问题标题】:Moving a DIV using only CSS仅使用 CSS 移动 DIV
【发布时间】:2019-02-26 14:10:44
【问题描述】:

我需要将一个 DIV 元素移动到正文的底部,但我无法修改 HTML 结构。我认为一些现有的线程可以帮助我,因为他们准确地解释了我在寻找什么,但它似乎不适用于我的情况:Moving a div from bottom to top, using only css。我可能遗漏了什么。

这是我的页面:https://www.tr-architecte.fr/page-220-auriples-drome

<section>
  <article class="container-fluid">
    <div class="row">...</div>
    <div class="txt">...</div>
    <div class="gallery">...</div>
  </article>
</section>

相关元素是DIV.txt。我希望将它放在 div.gallery 之后,但不能手动操作,因为照片库会在底部自动生成。不过我可以修改类和样式。

如果您需要更多信息,请告诉我。

【问题讨论】:

  • 我的错误。我用代码示例编辑了问题。对不起。

标签: html css bootstrap-4


【解决方案1】:

Flexbox 可以做到这一点:

.container-fluid {
  display: flex;
  flex-direction: column;
}

.container-fluid * {
  order: 1;
}

.txt {
  order: 2;
}
<section>
  <article class="container-fluid">
    <div class="row">1. Row</div>
    <div class="txt">2. Text</div>
    <div class="gallery">3. Gallery</div>
  </article>
</section>

【讨论】:

  • 效果很好!谢谢,那会很有用!
【解决方案2】:

如果你不能改变它粗糙的 html 结构,我会有一个解决方案。

不是最好的,我不推荐它,但它就是这样:

position: absolute;

这发生在 div 上,类 .row 包含您的文本。在绝对位置之后,您必须使用bottom: - something pxleft: something px。然后你用 id: social 进入你的 div 并生成一些padding-top: something px

我用来测试的是:

这个在.row

position: absolute;
left: 450px;
bottom: -535px;

这是#social

padding-top: 200px;

正如我所说,这是一种不好的做法,我不建议这样做,但由于您无权访问 html,因此这是您的选择。

【讨论】:

  • display:flex 似乎更合适,也不那么“粗糙”。我想我用过一次,但不记得在哪里以及如何使用它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-31
  • 2013-04-01
相关资源
最近更新 更多