根据屏幕/窗口方向对进行排序
我想知道一种根据移动设备中的屏幕方向或台式计算机中的窗口大小来排序 div 的方法。我有两个 div,我想知道是否有办法根据浏览器可用屏幕的分布来修改它们的行为。
例如,当它们处于水平位置时,我希望它们表现得像这样:
---------------- ----------------
| || |
| || |
| || |
| div1 || div2 |
| || |
| || |
| || |
---------------- -----------------
当它们处于垂直位置时,像这样:
----------------
| |
| |
| |
| div1 |
| |
| |
| |
----------------
----------------
| |
| |
| |
| div2 |
| |
| |
| |
----------------
我很想听听您的意见。
I was wondering about a way to order divs according to screen orientation in mobile devices or window size in desktop computers. I have two div's and I was wondering if there's a way to modify their behavior depending on the distribution of the browser's available screen.
For instance when, they're in a horizontal position I want them to behave like this:
---------------- ----------------
| || |
| || |
| || |
| div1 || div2 |
| || |
| || |
| || |
---------------- -----------------
when they're in a vertical position, like this:
----------------
| |
| |
| |
| div1 |
| |
| |
| |
----------------
----------------
| |
| |
| |
| div2 |
| |
| |
| |
----------------
I'd love to hear your opinion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 CSS 媒体查询!
它允许您指定在某些条件下(在本例中是窗口尺寸的变化)要应用的 CSS。
查看此链接:
http://css-tricks.com /snippets/css/media-queries-for-standard-devices/
我建议在 CSS 文件顶部完成所有常规样式设置,然后在底部应用媒体查询。对于您的情况,在每个媒体查询中,您将指定该特定场景所需的行为/定位。
用法示例:
上述语句意味着,对于 980 像素以下的所有分辨率,应用此样式。如果您执行以下操作:
这会将给定的CSS应用于从320px到480px的所有分辨率。
同样,仅应用最小宽度 XX 将为所有 XX 及以上分辨率应用给定的 CSS。
Use the CSS media query!
It allows you to specify what CSS you want applied under certain conditions (in this case, changes in window dimensions).
Check out this link:
http://css-tricks.com/snippets/css/media-queries-for-standard-devices/
What I would suggest is do all of your general styling at the top of your CSS file, then apply the media queries at the bottom. For your case, within each media query, you would specify the behavior/positioning you want for that specific scenario.
Sample Usage:
The above statement means, for all resolutions UP TO 980px, apply this styling. If you do something like:
This will apply the given CSS for all resolutions from 320px up to 480px.
Similarly, only applying a min-width of XX will apply a given CSS for all resolutions XX and above.
只需将它们浮动即可,如果屏幕太窄,它们会适当下降。
如果您希望它们仅适用于移动设备。检测您的移动浏览器并将 .mobile 附加到您的正文,或完全加载移动 css 文件。
Simply float them, if the screen is too narrow, they'll drop down appropriately.
If you wanted them stacked for mobile only. detect your mobile browser and append .mobile to your body, or load a mobile css file completely.