html - 用两个盒子简单响应?

标签 html css responsive-design

我有以下示例:http://jsfiddle.net/dwDZx/10/

html

<div id="container">
    <div id="div1" class="regularContainer">
        <div>one</div>
    </div>
    <div id="div2" class="regularContainer">
        <div>two</div>
    </div>
</div>​ 

CSS

* {
  margin:0;
  padding:0;
}

#div1 {
  float:left;
  margin-right:2%;
  margin-bottom:10px;
  max-width:300px;
  width:47%;
  background-color:#d3edff;
  border-color:#00b5ff;
  padding-bottom:8px;
}

#div2 {
  float:left;
  max-width:300px;
  width:47%;
}

.regularContainer {
  float:left;
  padding:7px;
  background-color:#fff;
  border:1px solid #00b5ff;
  width:784px;
}

​ 问题是,直到第二个框落下一行后,框才会调整大小?我需要的是盒子总是可以调整大小并且永远不会掉下来。

如何做到这一点?

最佳答案

仅使用百分比,它就会变得响应式。

这里是响应式http://jsfiddle.net/dwDZx/11/

我将之前的宽度更改为 45%,并将内边距更改为 1%

* { margin: 0; padding: 0; }

#div1
{
    float:              left;
    margin-right:       2%;         
    margin-bottom:      10px;
    max-width:          300px;
    width:              45%;
    background-color:   #d3edff;
    border-color:       #00b5ff;
    padding-bottom:     8px;
}

#div2
{
    float:              left;
    max-width:          300px;
    width:              45%; 
}

.regularContainer
{
    float:                      left;
    padding:                    1%;
    background-color:           #ffffff;
    border:                     1px solid #00b5ff;
    width:                      784px;
}

关于html - 用两个盒子简单响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14001954/

相关文章:

javascript - 仅在桌面版加载图像

html - 无法通过扩展子菜单扩展菜单

javascript - 语义 ui react 表 GridView float 卡问题

html - 底部 body 上的盒子阴影

html - 流体表是否有可能在每个元素之间和外部具有相同的间距?

javascript - 格式化从 JSON 文件接收数据的 React 表

css - 对齐中心搞乱定义列表

html - 编写媒体查询以根据屏幕尺寸有选择地加载图像

javascript - 需要 JavaScript 和从数组创建 html 表的帮助

html - float div 不考虑高度值的问题