css - 响应式布局,其中左列可能会向右移动

标签 css responsive-design flexbox

假设我们有一个包含 3 列的响应式设计(所有 3 列都是动态内容,所以我们不知道它们的高度)

对于桌面:

enter image description here

对于平板电脑(左列向右移动)

enter image description here

实现这一目标的最佳方式是什么? (我不介意使用 flexbox 或其他现代 css 规范)

最佳答案

你可以让元素float: left在桌面上各有1/3的宽度,然后在平板电脑/手机上给它们50%的宽度并让1和3float: right

HTML:

<div class="b1">
  1
</div>
<div class="b2">
  2
</div>
<div class="b3">
  3
</div>

CSS:

div {
  float: left;
  width: calc(100%/3);
  box-sizing: border-box;
}

@media (max-width: 600px) {
  div {
    width: 50%;
  }
  .b1,
  .b3 {
    float: right;
  }
}

Working JSFiddle

关于css - 响应式布局,其中左列可能会向右移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34285533/

相关文章:

javascript - 如何在 jquery 中向 $(window).resize 事件添加 if 条件?

html - 页脚链接在悬停时抖动/移动

html - 如何将 'X' 按钮移动到右侧末尾(与文本左侧内联)?

javascript - 响应式移动导航栏(导航)jquery/javascript

html - Flexbox 列子元素拉伸(stretch)页面而不是使用 overflow-y

css - 位置 : -webkit-sticky works only uptill the height of the container within a flexbox child on Safari(12. 1.1)

css - flex 的 child 的 child 占据了所有的空间

html - 如何使用 bootstrap 创建一个包含 9 列的行而不让数据溢出?

html - 如何设置 Rails 的 'number_field_tag' 样式?

html - 手机版网站无法显示完整内容