纯CSS框以特定方式折叠

时间:2015-04-21 09:20:02

标签: html css responsive-design

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

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

  1. 按钮组B崩溃
  2. 横幅崩溃
  3. 如果屏幕分辨率超高我想在左边有红色+标志(红色+绿色),中间有空白区域,右边有两个按钮组(蓝色+紫色)

    见下图:

    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解决我的问题吗?

    任何帮助将不胜感激

2 个答案:

答案 0 :(得分:2)

您可以使用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;
    }
}

您可以替换值以满足您的需求

答案 1 :(得分:0)

您需要的是display:flex

您可以定义flex-shrink / grow并将其与灵活元素上的最大和最小宽度相结合。

你可以将它与媒体查询结合起来