简体   繁体   中英

Responsive css tiles stack in pyramid shape

I have a row of 3 inline-blocks the span the width of the page horizontally:

在此输入图像描述

When the page reaches 1000px wide I want the tiles to stack themselves as a pyramid:

在此输入图像描述

And then at 460px they need to stack vertically:

在此输入图像描述

My current html/css structure is:

<div class='tile-row'>
    <div class='tile'></div>
    <div class='tile'></div>
    <div class='tile'></div>
</div>

.tile-row{
    margin: 0 auto;
    max-width:1485px;
}

.tile{
    width:32%;
    display: inline-block;
    height: 200px;
}

How would I set up media queries to accomplish the above scenarios? Is there an easier way to do this without using media queries?

Fiddle: http://jsfiddle.net/C2pjx/


 .tile-row{
      margin: 0 auto;
 }

.tile{
    width:32%;
    float: left;
    height: 100px;
    background: red;
    margin-left:10px;
    margin-bottom: 10px;
 }

 @media only screen and (max-width: 1000px) {
   .tile-row > div:nth-of-type(1)
    {
        float: none;
        margin: 10px 100px;

    }
 }
 @media only screen and (max-width: 460px) {
    .tile-row > div:nth-of-type(1){
        margin: 10px 0;
    }
    .tile{
        float:none;
        background: blue;
        margin: 10px 0;
    }

 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM