在 CSS3 媒体查询中使用浮动
我正在我的响应式网站上工作,其中 Html 结构如下:
<div id="container">
<div id="first">FIRST</div>
<div id="second">SECOND</div>
<div id="third">THIRD</div>
</div>
Div #First、#Second & #Third 有 float : left
因此,当浏览器宽度超过 1280px 时,它们按以下顺序出现:
== 1 == 2 == 3 ==
&当浏览器宽度小于 767px 时,它们会缩小宽度并缩小宽度。根据我的 css3 媒体查询,一个出现在另一个下面:
== 1 ==
== 2 ==
== 3 ==
我想要实现的是,当浏览器宽度小于 767px 时,它们的顺序应该是:
== 1 = =
== 3 ==
== 2 ==
可以看到DOM结构 Jsbin 这里
我怎样才能用纯CSS3实现这一点?
I'm working on my responsive site where Html structure is like this :
<div id="container">
<div id="first">FIRST</div>
<div id="second">SECOND</div>
<div id="third">THIRD</div>
</div>
Div #First, #Second & #Third have float : left
So, When Browser width is more than 1280px They appears in following order :
== 1 == 2 == 3 ==
& When Browser width is less than 767px, They shrinks in width & appears one below the other as per my css3 media queries:
== 1 ==
== 2 ==
== 3 ==
What I want to achieve is, When Browser width is less than 767px their order should be :
== 1 ==
== 3 ==
== 2 ==
You can see DOM Structure Jsbin Here
How can I achieve this with pure CSS3 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将第三个和第二个向右浮动并按照您想要的方式重新排序它们,这里是 jsbin
Html:
try floating the third and second right and reordering them like you want here is jsbin
Html:
你还不能用 CSS 做到这一点......
如果任何浏览器支持高级布局模块,您可以这样做:
You can't do that with CSS... yet.
If any browser supported the advanced layout module you could do this:
好吧,这个解决方案依赖于知道每个 div 的高度。如果您事先不知道高度,则需要使用 javascript 来获取高度并在那里应用您的更改。
代码如下:
将它们的位置设置为相对位置并指定 top 属性。为了使第三个元素与第二个元素切换,您必须为其指定第二个元素高度的负顶部值。然后,您只需为第二个元素指定一个等于第三个元素高度的顶部值即可。这将导致它们在您的布局中交换位置。
Alright, this solution is dependent on knowing the height of each div. If you don't know the height beforehand, you would need to use javascript to get the height and apply your changes there.
Here's the code:
You set their positions to relative and specify the top property. For the third element to switch with the second, you have to give it a negative top value of the second element's height. Then you simply give the second element a top value equal to the third element's height. That will cause them to switch places in your layout.