#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>
是他们的一种方法,我可以改变的div的基于设备的,我浏览我的网站上的类型的命令?我正在尝试创建一个响应式设计。我创建了这个非常简单的样本,基本上有3个div。他们在桌面上依次为1,2,3。我在我的CSS中添加了媒体查询来处理移动设备。我希望订单从2,1,3改变。我确信必须有一种方法才能用CSS来实现这一点,但我对此不够熟悉。有任何想法吗?由于
<!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>
我想你可以尝试使用Flexbox的(https://css-tricks.com/snippets/css/a-guide -to-flexbox /):查看订单属性。 –
谢谢,订单属性看起来像我需要但它似乎不支持IE 9,我可能需要 – Scott
恐怕,如果您需要支持IE9,最好的事情是使用一些JavaScript。 –