#div1 {
position: relative;
max-width: 100%;
height: 100px;
background-color: green;
color: white;
}
#div2 {
position: relative;
max-width: 100%;
height: 100px;
background-color: red;
color: white;
}
#div3 {
position: relative;
max-width: 100%;
height: 100px;
background-color: blue;
color: white;
}
@media (max-width: 400px) {
#div1 {
position: absolute;
max-width: 100%;
height: 100px;
background-color: green;
color: white;
}
#div2 {
position: absolute;
left: 0;
max-width: 100%;
height: 100px;
background-color: red;
color: white;
}
#div3 {
position: relative;
max-width: 100%;
height: 100px;
background-color: blue;
color: white;
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title></title>
<meta charset="utf-8" />
<body>
<div id="div1">
<h1>Box 1</h1>
</div>
<div id="div2">
<h1>Box 2</h1>
</div>
<div id="div2">
<h1>Box 3</h1>
</div>
</body>
</html>
Is it possible to rearrange the order of divs based on the device I am viewing my site on? I am striving for a responsive design. The current layout has 3 divs placed in ascending order on desktop view, but I would like to change the order to 2, 1, 3 for mobile devices. Is there a way to achieve this using only CSS? I lack expertise in this area and would appreciate any suggestions or solutions. Thank you!
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title></title>
<meta charset="utf-8" />
<style>
#div1 {
position: relative;
max-width: 100%;
height: 100px;
background-color: green;
color: white;
}
#div2 {
position: relative;
max-width: 100%;
height: 100px;
background-color: red;
color: white;
}
#div3 {
position: relative;
max-width: 100%;
height: 100px;
background-color: blue;
color: white;
}
@media (max-width: 400px) {
#div1 {
position: absolute;
max-width: 100%;
height: 100px;
background-color: green;
color: white;
}
#div2 {
position: absolute;
left: 0;
max-width: 100%;
height: 100px;
background-color: red;
color: white;
}
#div3 {
position: relative;
max-width: 100%;
height: 100px;
background-color: blue;
color: white;
}
}
</style>
</head>
<body>
<div id="div1">
<h1>Box 1</h1>
</div>
<div id="div2">
<h1>Box 2</h1>
</div>
<div id="div2">
<h1>Box 3</h1>
</div>
</body>
</html>