jquery - 为什么 css 100% - 100% 没有 absolute 就不能工作?

标签 jquery html css

问题 1) 我有这个 http://jsfiddle.net/Qx9uG/1/ 使用绝对。当我删除绝对值时, http://jsfiddle.net/Qx9uG 它不起作用。这是为什么?

问题 2)如果我将宽度从 % 更改为 px,将高度 px 更改为 %,为什么我得不到结果?

http://jsfiddle.net/SGpb2/2/ http://jsfiddle.net/SGpb2/1/

.box
{
    width: 100%;
    height: 100%;
    background: red;
    position: absolute;
}

最佳答案

因为 0100% 也是 0

定义父元素,在本例中为 body/html

jsFiddle example

html, body {
    height:100%;
}

它与绝对定位一起工作的原因是因为绝对定位的元素从文档流中取出,因此不需要定义它们父级的尺寸。

关于jquery - 为什么 css 100% - 100% 没有 absolute 就不能工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20157032/

相关文章:

html - 使用位置 :absolute within a three levels menu to display the last two levels on the right of each other avoiding stack them on each other

javascript - CSS - 添加任意未知属性名称是否合法?

javascript - 如何获取 ID 集合以及从 View 表传递到 Controller 的选定下拉列表值?

javascript - 停止移动下方内容的 jQuery 向下滑动效果?

Chrome Web 控制台中的 Javascript "Unexpected identifier"

html - AngularJS 指令中自定义 HTML 标签的后果

javascript - jQuery/JavaScript 比较最大值和最小值

jquery - Magento:添加外部 jQuery 文件

asp.net - 母版页继承网页的css

css - 类似 Pinterest 的网格