如何不改动html,通过css调换div区域的显示顺序

caidong_123 2017-12-12 02:23:40
有一串代码如下:
<section class="post clearfix"> this is the first line code </section>
<section class="post clearfix"> this is the second line code </section>
电脑上是上下排列显示的,现在我想不改动上面html的代码顺序,通过css或者js来将这两个div调换顺序,如何能做到?

注: float 尝试过不行
求大神帮助,在线等
...全文
465 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
whidy 2017-12-13
  • 打赏
  • 举报
回复
CSS目前没有实现,JS我写了一个你看看根据需求调整一下.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>reorder lines</title>
  <style>
    .post:nth-child(2n+1) {
      color: red;
    }
  </style>
</head>
<body>
  <div id="par">
    <section class="post"> this is the 1st line code </section>
    <section class="post"> this is the 2nd line code </section>
  </div>
  <script>
    var p = document.getElementById('par');
    var lines = p.getElementsByTagName('section');
    p.insertBefore(lines[1], lines[0]);
  </script>
</body>
</html>
天际的海浪 2017-12-12
  • 打赏
  • 举报
回复
用css伸缩盒
zy35 2017-12-12
  • 打赏
  • 举报
回复
左浮动不行可能是因为你的两个DIV的距离已经超过你规定的距离或者屏幕本身的高度,可以先定样式,再弄左浮动

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧