css 响应框宽度 90% * 95% with 5% 5% 0 5% margin

标签 css responsive-design percentage

我想要实现的是:

这似乎是不可能的。尝试了很多可能性。他们都没有工作。这是我认为应该有效的方法。

<div id="wrap">
    <div id="content">hello</div>
</div>

html,body{
    height:100%;
}

    #wrap{
        background-color:red;
        width:100%;
        height:100%;
    }

    #content{
        background-color:cyan;
        width:90%;
        height:95%;
        margin: 5% 5% 0 5%;
    }

直播:http://jsfiddle.net/vjb45/

最佳答案

一种方法(简单且小巧)是在容器上使用 css 属性 - box-sizing:border-box:例如 http://jsfiddle.net/6EfeC/

此 css 将允许您将边距/填充和宽度的完整值组合到一个单元中。

html,body{
    height:100%;
}

#wrap{
    background-color:red;
    width:100%;
    height:100%;
    box-sizing:border-box;
        /* for current ffox */
        -moz-box-sizing:border-box;
    padding:2.5% 5%;
}

#content{
    background-color:cyan;
    height:100%;
}

检查 - availablity和供应商前缀。例如

-moz-box-sizing:border-box

关于css 响应框宽度 90% * 95% with 5% 5% 0 5% margin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22880838/

相关文章:

html - 将一个 div 重叠在另一个之上

CSS 计数器在 IE9 中失败,但可以通过 IE devtools 修复?

css - 在 Neo4j 2.0.0 中设置关系的标题。浏览器

css - 带有三 Angular 形的 Navbar 上不需要的边框

python - Pandas :如何获得每一行的百分比

html - 如何使用百分比居中?

javascript - 元素 - 响应表问题

javascript - 在一定比例的窗口大小上不断更改 div 大小

r - 如何将数字格式化为百分比值但仍然能够以数字方式处理它?

mysql - 使用 GROUP BY 计算 COUNT 的百分比