第一种方法: 使用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>
第二种方法 :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>