如何通过样式叠加将一个部分置于另一个部分之上,同时保持它们的位置不变
P粉958986070
P粉958986070 2023-09-08 13:03:04
[CSS3讨论组]

考虑以下我的html代码

<html>
<head>
</head>
<body>
    <div class="wrapper">
        <section class="first">第一内容</div>
        <section class="second">第二内容</div>
        <section class="third">第三内容</div>
    </div>
</body>
</html>

我需要的是通过更改类名而不是在html中更改位置,将第三个内容显示在浏览器视图的顶部 同时,更改应保持响应性。

我的html代码如下

<div class="wrapper">
    <section class="third">第一内容</section>
    <section class="second">第二内容</section>
    <section class="first">第三内容</section>
</div>
P粉958986070
P粉958986070

全部回复(2)
P粉207483087

我会使用网格系统和顺序。然后使用js来改变顺序号,使第三个div变成第一个。你觉得这对你来说可能是一个解决方案吗?

你可以在这里找到更多信息:https://developer.mozilla.org/en-US/docs/Web/CSS/order

.wrapper{
display: grid;
}
.first{
order: 1;
}
.second{
order: 2;
}
.third{
order: 3;
}

然后你可以使用JS来改变顺序号

P粉204136428

.wrapper{
     display: flex;
     flex-flow: column;
}
 .first{
     order: 3;
}
 .second{
     order: 2;
}
 .third{
     order: 1;
}
<html>
<head>
</head>
<body>
    <div class="wrapper">
        <section class="first">First Content</section>
        <section class="second">Second Content</section>
        <section class="third">ThirdContent</section>
    </div>
</body>
</html>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号