CSS实现两个元素调换位置

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6


第一种方法: 使用transform

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<style>
.test{
display:flex;
float :right
}
.div1
{
width:200px;
height:100px;
background-color:red;
-webkit-transform:translateX(100%); /* Safari and Chrome */
}


.div2
{
width:200px;
height:100px;
background-color:yellow;
-webkit-transform:translateX(-100%); /* Safari and Chrome */
}
</style>
</head>
<body>
<div class="test">
<div class="div1">div1</div>
<div class="div2">div2</div>
</div>

</body>
</html>

CSS实现两个元素调换位置_Chrome

第二种方法 :flex-direction:row-reverse;

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<style>
#main {
display: flex;
flex-direction:row-reverse;
}

#main div {
width: 40px;
height: 40px;
}
</style>
</head>
<body>

<div id="main">
<div style="background-color:coral;">A</div>
<div style="background-color:lightblue;">B</div>
<div style="background-color:khaki;">C</div>
<div style="background-color:pink;">D</div>
<div style="background-color:lightgrey;">E</div>
<div style="background-color:lightgreen;">F</div>
</div>

</body>
</html>

CSS实现两个元素调换位置_html_02


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: CSS