html - 纯 CSS 框以特定方式折叠

标签 html css responsive-design

我需要折叠 div(左: Logo 、横幅,右:按钮组 A、按钮组 B)

我希望这些根据屏幕尺寸以特定方式折叠:

  1. B 组折叠按钮
  2. 横幅折叠

如果屏幕分辨率超高我想左边有banner+logo(红+绿),中间空白,右边两个按钮组(蓝+紫)

见下图:

enter image description here

这是我目前尝试过的:

https://jsfiddle.net/ey74wud6/

老实说这是反复试验,盒子折叠的方式对我不利。

<style>
    /* just example - color, fixed size of box */
    .green { background: green; width: 80px; height: 70px; }
    .red { background: red; width: 270px; height: 70px; }    
    .purple { background: purple; width: 70px; height: 70px; }
    .blue { background: blue; width: 70px; height: 70px; }
    .box { margin: 2px; }

    /* proper css experiments */

    .left {
        float: left;
    }

    .left .box {
        float: left;
    }

    .right {
        float: right;
    }

    .right .box {
        float: left;
    }
</style>

<div class="left">        
    <div class="box green"></div>
</div>

<div class="left">        
    <div class="box red"></div>
</div>

<div class="right">        
    <div class="box purple"></div>
</div>

<div class="right">        
    <div class="box blue"></div>
</div>

我知道我可以在 javascript 的帮助下做到这一点,但我的问题是可以使用纯 CSS 解决我的问题吗?

任何帮助将不胜感激

最佳答案

您可以为此使用 css 媒体查询。查看修改后的示例:https://jsfiddle.net/ey74wud6/1/

我稍微修改了你的 css 代码,但最重要的部分是:

@media (max-width: 454px) {
    .left {
         width : 280px;
    }

    .right {
        width: 80px;
    }
}

@media (min-width: 455px) and (max-width: 522px) {
    .left {
         width : 360px;
    }

    .right {
        width: 80px;
    }
}

您可以根据需要替换值

关于html - 纯 CSS 框以特定方式折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29767955/

相关文章:

javascript - 根据屏幕大小更改 $scope 变量

css - 在css中使用url设置背景图像的不透明度

html - block <a> 中的图像显示 - CSS

javascript - reactjs组件中if(x)和if(x==true)的区别

javascript - 使用媒体查询在较小的屏幕上仅滚动模态的距离

java - 生成Javadoc以便在手机上轻松使用

html - Symfony2 - 渲染模板时获取外部内容

css - 如何使用CSS更改第一个表格第一行的颜色

css - 在另一个 div 之上创建一个 div 索引,并且两者都在包装器中

css - 在 &lt;textarea&gt; 中格式化文本?