html - border overflow 100% height width body 移动浏览器?

标签 html css mobile

我有以下 DIV 结构:

<style>
#header{border-bottom:1px solid blue;}
#footer{botter-top:1px solid blue;}
#header,#footer{height:15%;}
#content{height:70%;}
#header,#footer,#content{width:100%;}
</style>

<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>

我注意到的是,在桌面浏览器中,有一个预期的溢出,从 100% 偏移 2px+ 但是,在移动浏览器中,似乎没有任何溢出/滚动。

  • 移动设备是否将边框计为 100% 高度/宽度计算的一部分?

如果是:

  • 有没有办法通过桌面浏览器的 CSS 调用此行为?
  • 有没有办法通过适用于移动浏览器的 CSS 来扭转这种行为?

最佳答案

所以是的,桌面浏览器会看到 2px 的偏移量,因为规范说采用 100% 的父级 + 边框 + 边距。移动浏览器似乎没有受到影响,但主要是因为它们试图将内容自动调整到窗口以消除滚动。

有 2 个 css3 修复,第一个是使用新的 box-sizing 属性,并将其设置为 border-box。第二种是使用flexbox模型。但不幸的是,较旧的浏览器可能不支持这两种解决方案。

所以我会使用 box-sizing,但是放入一个 IE 条件语句来说明 IE7 和返回,然后只使用 javascript 或 css hack 来修复它。

编辑

这里是使用 box-sizing http://jsfiddle.net/aaFHZ/ 的解决方案

body, html {height:100%; width: 100%;}
#header{border-bottom:1px solid blue;}
#footer{border-top:1px solid blue;}
#header,#footer{height:15%;}
#content{height:70%;}
#header,#footer,#content{width:100%; box-sizing:border-box;}

这里是 flexbox 的解决方案(注意:这只适用于最新的浏览器)http://jsfiddle.net/YkSYN/1/

<style>
body, html {height:100%; width: 100%;}
#header{border-bottom:1px solid blue;}
#footer{border-top:1px solid blue;}
#header,#footer {
    -webkit-box-flex: 15;
    -moz-box-flex: 15;
    box-flex: 15;}
#content {
    -webkit-box-flex: 70;
    -moz-box-flex: 70;
    box-flex: 70;}
#header,#footer,#content{width:100%;}
#wrapper {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    display: -moz-box;
    -moz-box-orient: vertical;
    display: box;
    box-orient: vertical;
    width: 100%; 
    height:100%;}
</style>
<div id="wrapper">
    <div id="header"></div>
    <div id="content"></div>
    <div id="footer"></div>
</div>​

关于html - border overflow 100% height width body 移动浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12682549/

相关文章:

PHP 代码被注释掉

javascript - 尝试在单选按钮上获取鼠标悬停事件

javascript - 为什么我的棋盘不使用 flexbox 环绕?

javascript - 如何功能检测限制滚动事件的浏览器?

c# - 通过 asp.net 中的代码隐藏将按钮添加到网页并删除动态数据库条目

html - 由于背景图片,css 样式的单选按钮不起作用

css - 中心 CSS 按钮宽度自动

css - SVG 过滤器中的大模糊在 Safari 中不起作用

flutter - flutter 条件背景图像添加

java - 以编程方式清除应用程序缓存?