Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在html中切换两个div_Html_Css - Fatal编程技术网

如何在html中切换两个div

如何在html中切换两个div,html,css,Html,Css,假设我有两个相互重叠的div,我想交换两个div。不做任何代码更改。 如何交换两个div?是否要交换div的可见性?使用z索引,您可以将一个div置于另一个div之上 .红色,.蓝色{ 宽度:200px; 高度:100px; 位置:绝对位置; } 瑞德先生{ 背景:红色; z指数:1; } 蓝先生{ 背景:蓝色; 顶部:50px; } 您可以使用flexbox排序来完成此任务 发件人: order CSS属性设置项目在flex或CSS中的布局顺序 网格容器。容器中的项目按升序排序 值,然后按其

假设我有两个相互重叠的div,我想交换两个div。不做任何代码更改。
如何交换两个div?

是否要交换div的可见性?使用z索引,您可以将一个div置于另一个div之上

.红色,.蓝色{ 宽度:200px; 高度:100px; 位置:绝对位置; } 瑞德先生{ 背景:红色; z指数:1; } 蓝先生{ 背景:蓝色; 顶部:50px; } 您可以使用flexbox排序来完成此任务

发件人:

order CSS属性设置项目在flex或CSS中的布局顺序 网格容器。容器中的项目按升序排序 值,然后按其源代码顺序

看看这个演示。以“整页”模式打开它,并将屏幕大小调整到小于400px,以便框开始重叠。通过使用排序,我交换或切换了div,而不需要任何JavaScript

html,正文{ 保证金:0; } .集装箱{ 显示器:flex; 宽度:500px; 最大宽度:100%; 边框:1px纯红; 证明内容:之间的空间; } .容器>*{ 位置:相对位置; 宽度:200px; 高度:100px; } .container>*::之后{ 位置:绝对位置; 底部:-1.5em; 左:50%; 转化:translateX-50%; 颜色:黑色; } .左{ 背景颜色:绿色; } .左::后{ 内容:"左";; } .对{ 背景颜色:蓝色; } 在…之后{ 内容:"对";; } @媒体屏幕和最大宽度:400px{ .左{ 顺序:1; } .左::后{ 内容:"对";; } 在…之后{ 内容:"左";; } }
您可以使用Z索引来解决此问题

<!DOCTYPE html>
<html>
<head>
<style>
img {
  position: absolute;
  left: 0px;
  top: 0px;
  z-index: -1;
}
</style>
</head>
<body>

<h1>The z-index Property</h1>

<img src="w3css.gif" width="100" height="140">

<p>Because the image has a z-index of -1, it will be placed behind the heading.</p>

</body>
</html>

请看:。以哪种方式交换?不做任何代码更改,我看不到任何代码