根据屏幕/窗口方向对
进行排序

发布于 2025-01-02 03:48:35 字数 899 浏览 3 评论 0原文

我想知道一种根据移动设备中的屏幕方向或台式计算机中的窗口大小来排序 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白色秋天 2025-01-09 03:48:35

使用 CSS 媒体查询!

它允许您指定在某些条件下(在本例中是窗口尺寸的变化)要应用的 CSS。

查看此链接:

http://css-tricks.com /snippets/css/media-queries-for-standard-devices/

我建议在 CSS 文件顶部完成所有常规样式设置,然后在底部应用媒体查询。对于您的情况,在每个媒体查询中,您将指定该特定场景所需的行为/定位。

用法示例:

@media screen and (max-width: 980px) { ...css... }

上述语句意味着,对于 980 像素以下的所有分辨率,应用此样式。如果您执行以下操作:

@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) { ...css... }

这会将给定的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:

@media screen and (max-width: 980px) { ...css... }

The above statement means, for all resolutions UP TO 980px, apply this styling. If you do something like:

@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) { ...css... }

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.

败给现实 2025-01-09 03:48:35

只需将它们浮动即可,如果屏幕太窄,它们会适当下降。

div {
    float:left;
}

如果您希望它们仅适用于移动设备。检测您的移动浏览器并将 .mobile 附加到您的正文,或完全加载移动 css 文件。

div {
    float:left;
}

.mobile div {
    clear:both;
}

Simply float them, if the screen is too narrow, they'll drop down appropriately.

div {
    float:left;
}

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.

div {
    float:left;
}

.mobile div {
    clear:both;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文