css - 自动调整 2 个 div 从列到行的大小,同时保持全宽

标签 css html

是否可以自动调整 2 列 div 的大小,以便满足以下条件:

每列自动调整为显示宽度的 50% 左右。 每列的最小宽度约为 200 像素。 当任一列/两列都小于最小宽度时,将右侧 div 直接放在左侧 div 下方,并将两个 div 自动调整为显示的全宽。

这个想法是桌面和表格(400 像素及更宽)将显示 2 列:

Width >= 400px
+-------+-------+
|  50%  |  50%  |
+-------+-------+
  div1    div2

较小的显示屏将显示 2 行:

Width < 400px
+---------------+
|     100%      |  div1
+---------------+
|     100%      |  div2
+---------------+

最佳答案

纯CSS解决方案:

CSS:

html, body, .container {
    width: 100%;
    margin: 0;
    padding: 0;
}
.content {
    display: inline-block;
    width: 50%;
    border: 2px solid #f0f;
    background-color: #0ff;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box; 
}
@media only screen and (max-width: 400px) {
    .content {
        display:block;
        width: 100%;
     }
}

HTML:

<div class="container">
    <div class="content">
        Content
    </div><!--
    --><div class="content">
        Content
    </div>
</div>

演示:http://jsfiddle.net/LUBpF/1/

关于css - 自动调整 2 个 div 从列到行的大小,同时保持全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20980137/

相关文章:

css - 如何在 CSS 中容纳两个盒子

html - 输入尺寸与宽度

html - Bootstrap 形式的行之间的空间不正确

html - 如何打印适合定义纸张尺寸的内容?

java - 如何从html页面生成下载请求到spring mvc的 Controller

html - 谷歌地图未显示在 div 中

HTML 固定列宽在 MS Outlook 中无法正常工作

jquery - 现在可以使用有效的 HTML5 吗?

javascript - 为什么 aframe 中的视频无法在移动设备上播放

html - SPAN 中的新行