3列响应CSS(订购内容位置)

Exh*_*ted 6 html css layout stylesheet responsive-design

我想知道当屏幕尺寸减小到480或更低时,有没有办法订购内容位置.我的意思是在第3栏我会有名字,号码和地址等,在第2栏我将有社交内容和第1列我将有一个图像.我想首先将名称和地址叠加,然后是图像,然后是社交图标.订单将是3,1,2.我试图让它保持响应.

CSS:

/*  SECTIONS  */
.section {
clear: both;
padding: 0px;
margin: 0px;
} 

/*  COLUMN SETUP  */
.col {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.col:first-child { margin-left: 0; }


/*  GRID OF THREE           ============================================================================= */


.span_3_of_3 {
width: 100%; 
}

.span_2_of_3 {
width: 66.1%; 
}

.span_1_of_3 {
width: 32.2%; 
}


 /*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

 @media only screen and (max-width: 480px) {
.span_3_of_3 {
    width: 100%; 
}
.span_2_of_3 {
    width: 100%; 
}
.span_1_of_3 {
    width: 100%;
}
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<div class="section group">
<div class="col span_1_of_3">
This is column 1
</div>
<div class="col span_1_of_3">
This is column 2
</div>
<div class="col span_1_of_3">
This is column 3
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

cim*_*non 16

优化移动设备的源订单会更有效,并使用metadept的解决方案重新排序桌面列.

但是,如果无论出于何种原因无法修改源订单,或者您不知道要重新排序的元素的宽度,那么您需要Flexbox:

http://jsfiddle.net/4KUUt/3/

/*  SECTIONS  */
/* line 5, ../sass/test.scss */
.section {
  clear: both;
  padding: 0px;
  margin: 0px;
}

/* line 11, ../sass/test.scss */
.a {
  background-color: #CCF;
}

/* line 14, ../sass/test.scss */
.b {
  background-color: #CFC;
}

/* line 17, ../sass/test.scss */
.c {
  background-color: #FCC;
}

/*  GRID OF THREE           ============================================================================= */
@media only screen and (min-width: 480px) {
  /* line 24, ../sass/test.scss */
  .span_3_of_3 {
    width: 100%;
  }

  /* line 28, ../sass/test.scss */
  .span_2_of_3 {
    width: 66.1%;
  }

  /* line 32, ../sass/test.scss */
  .span_1_of_3 {
    width: 32.2%;
  }

  /*  COLUMN SETUP  */
  /* line 37, ../sass/test.scss */
  .col {
    display: block;
    float: left;
    margin: 1% 0 1% 1.6%;
  }

  /* line 42, ../sass/test.scss */
  .col:first-child {
    margin-left: 0;
  }
}
@media only screen and (max-width: 480px) {
  /* line 48, ../sass/test.scss */
  .section {
    width: 100%; /* fix for Firefox */
    display: -webkit-box;
    display: -moz-box;
    display: -webkit-flexbox;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-orient: vertical;
    -moz-box-orient: vertical;
    -webkit-box-direction: normal;
    -moz-box-direction: normal;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
  }

  /* line 53, ../sass/test.scss */
  .a {
    -webkit-box-ordinal-group: 2;
    -moz-box-ordinal-group: 2;
    -webkit-flex-order: 1;
    -ms-flex-order: 1;
    -webkit-order: 1;
    order: 1;
  }

  /* line 57, ../sass/test.scss */
  .b {
    -webkit-box-ordinal-group: 3;
    -moz-box-ordinal-group: 3;
    -webkit-flex-order: 2;
    -ms-flex-order: 2;
    -webkit-order: 2;
    order: 2;
  }
}


<div class="section group">
    <div class="col span_1_of_3 a">This is column 1</div>
    <div class="col span_1_of_3 b">This is column 2</div>
    <div class="col span_1_of_3 c">This is column 3</div>
</div>
Run Code Online (Sandbox Code Playgroud)

请注意,我已将您的媒体查询修改为更高效.


met*_*ept 2

我在理解您的列顺序时遇到了一些麻烦,但在移动设备上重新排列它们的方法是使用边距“推”和“拉”。例如:

.span_1_of_3 {
    margin-left: 33%;
}

.span_2_of_3 {
    margin-left: -65%;
}
Run Code Online (Sandbox Code Playgroud)

这将使并排(桌面)布局中的第 2 列显示在第 1 列之前,然后您可以删除堆叠(移动)布局的边距。

请参阅此 jsFiddle:http://jsfiddle.net/4KUUt/

编辑2

我想我已经按照你想要的顺序设置了。如果您仍在寻找解决方案,请尝试以下操作: http: //jsfiddle.net/4KUUt/5/