我想知道如何做到这一点,我目前的标记如下:
<div id="playArea" style="position: relative;">
<div id="widget1" class="widget" style="position: absolute; left: 295px; top: -1px; width: 313px; height: 269px;">Hello</div>
<div id="widget2" class="widget" style="position: absolute; left: 63px; top: 35px; width: 80px; height: 42px;">World</div>
<div style="position: absolute; left: 534px; top: 329px; width: 183px; height: 251px;">Bye</div>
</div>
Run Code Online (Sandbox Code Playgroud)
现在,如果我在最后一个之后创建一个段落标记,则标记</div>的内容p不会出现在浏览器中的所有这些div下面.我有什么想法可以做到这一点?
多谢你们
我正在寻找针对此报告中描述的z-index错误的变通方法或polyfill:http: //code.google.com/p/android/issues/detail?id = 31862
我的标记和CSS看起来与bug报告中给出的基本相同.
如果有人能给我一个如何解决这个问题的正确方向的提示,真的很棒.
阿display: table-row与DIV height: 75px嵌套在内部display: table与格height: 100px
孩子的身高100px最初是position: static
通过将子元素的位置更改为absolute然后再返回到static,子项的高度将永久地从更改100px为75px.
只有当父元素是一个表而子元素是一个表行并且显然它只在WebKit中时才会出现; firefox/IE变回100px高度,但Chrome/Safari没有.
<div id="div1">
<div id="div2">
Hello, world!
</div>
</div>
#div1
{
display: table;
height: 100px;
}
#div2
{
display: table-row;
height: 75px;
}
Run Code Online (Sandbox Code Playgroud)
这是jsfiddle的示例和定位类型/高度的输出.
我最初通过在Chrome开发人员工具中搞乱CSS属性来注意到它,所以它不是特定于jsfiddle或jQuery的东西.
为什么高度会永久变化?
我有一个垂直滚动的布局.可滚动div中的一个子元素绝对定位具有较大的顶部值,从而在父级上引入垂直滚动条.可滚动的父div还有一些子div元素(让它们称为柱子),它们通过position:absolute和some left value水平相邻放置.
这是HTML标记:
<div id="root" style="height: 250px; position: relative;">
<div class="stretch">
<div id="container" class="container">
<div id="pillar1" style="left: 0.0%; width:33.25%;" class="pillar" ></div>
<div id="pillar2" style="left: 33.05%; width:33.25%;" class="pillar" ></div>
<div id="pillar3" style="left: 66.05%; width:33.25%;" class="pillar" ></div>
<div id="fixed-and-not-movable" style="background: blue; width: 25px; height: 25px; top:350px; left: 150px; position: absolute;">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和CSS:
.stretch {
bottom: 0;
left: 0;
right: 0;
top: 0;
position: absolute;
height: auto;
width: auto;
}
.container {
border: 2px solid;
bottom: 0;
left: 0;
right: 0; …Run Code Online (Sandbox Code Playgroud) I have a div for a header and a div for a content wrap.
For some reason, I can't have a margin on the bottom of the header that forces the content wrap to push down. It just ignores it completely and I have no idea why.
Does anyone know what is going on with this? It doesn't do this when I take away the position: fixed; attribute on the header, but I want it to be fixed …
我试图了解z-index的工作原理.为了做到这一点,我创建了一个由五个div组成的简单示例.每个人都是前一个孩子,除了第一个孩子.我的目标是使第一个div(所有其他div的父容器)显示在所有其他div之上,有效地隐藏它们.
为了实现我的目标,我已经在所有div和父div上放置了z-index属性我放了一个夸大的值100以确保它高于所有其他但它似乎没有工作.
我已经阅读了许多关于z-index的不同文档,并在Stack Overflow上阅读了大量的答案.到目前为止,我尝试了以下内容:
尽管如此,我还没有成功地使父div出现在所有其他div之上.我究竟做错了什么?
我用我刚才描述的例子创建了一个JSFiddle:https://jsfiddle.net/y8jfdz7w/15/ .
.first {
position: absolute;
z-index: 100;
width: 500px;
height: 500px;
background-color: grey;
}
.second {
position: absolute;
z-index: 2;
width: 450px;
height: 450px;
top: 25px;
left: 25px;
background-color: orange;
opacity: 0.99;
}
.third {
position: absolute;
z-index: 3;
width: 400px;
height: 400px;
top: 25px;
left: 25px;
background-color: yellow;
opacity: 0.99;
}
.fourth {
position: absolute;
z-index: 20;
width: 350px;
height: 350px;
top: 25px;
left: 25px;
background-color: green;
opacity: …Run Code Online (Sandbox Code Playgroud)这是谷歌翻译的iframe代码.
<div id="contentframe" style="top: 160px; left: 0px;">
<iframe src="/translate_p?hl=en&ie=UTF8&prev=_t&sl=auto&tl=en&u=http://yahoo.co.jp/&depth=1&usg=ALkJrhjrVT6Mc1tnruB-zgrtu9cyQ1bSeA" name="c" frameborder="0" style="height:100%;width:100%;position:absolute;top:0px;bottom:0px;"></div>
</iframe></div>
Run Code Online (Sandbox Code Playgroud)
我尝试使用相同的div和iframe标签做类似的事情,但html页面最终不像谷歌翻译.
<div id="contentframe" style="top: 160px; left: 0px;">
<iframe src="http://stackoverflow.com" style="height:100%;width:100%;position:absolute;top:0px;bottom:0px;"></div>
</iframe></div>
Run Code Online (Sandbox Code Playgroud)
iframe显示在页面顶部,而不是出现160px之后,由div指定.
我不确定我的代码有什么问题,这与Google代码几乎相同.
编辑:添加位置:相对于标记不适合作为解决方案.它将div缩小为高度较小的条形.它还意味着不能指定相对于页面的确切位置.
我有一个固定的div与动态加载li元素.现在我希望div-content在有超过9个li元素和滚动条时滚动:
这就是它的样子:

此时固定div在页脚上继续,内容无法滚动.
这是所有人的CSS divs:
#fixed-div {
position: fixed;
width: 30%;
margin-top:290px;
padding-top:20px;
padding-bottom: 20px; /* must be same height as the footer */
background-color: rgba(255, 255, 255, 0.60);
min-height: 100%;
}
#absolute-div {
padding: 15px;
background-color: rgba(255, 255, 255, 0.60);
margin-bottom: 10px;
position: relative;
height: 200px;
}
#footer {
position: relative;
margin-top: -33px; /* negative value of footer height */
height: 20px;
line-height: 33px;
border-bottom:20px solid #fff;
text-align: left;
background-color:#fff;
padding-left:10px;
} …Run Code Online (Sandbox Code Playgroud) 
我一直在尝试布局这个页面,但对于我的生活,似乎无法让它以我想要的方式工作.
Window = black
Titlebar = red
Content div = blue
Vertical scrollbar = green
Horizontal scrollbar = yellow
Run Code Online (Sandbox Code Playgroud)
最小标题栏/内容div宽度为1024px,增长到窗口大小.
我可能完全过度思考它,答案可能比我尝试的简单得多.
基本上我想在页面顶部有一个永远不会垂直滚动的固定标题栏div.如果它不适合水平放入窗口,我希望水平滚动条滚动标题栏和内容.如果内容div高于窗口高度,我希望它滚动,否则我希望它扩展到页面的底部.
在大多数情况下,我几乎没有限制如何设置这些div,所以想象一下这是一个空白的板块.
只需要在最近的操作系统上使用现代浏览器.理想情况下,只有一个CSS/HTML修复,但如果绝对需要,将考虑一些JS.需要可见的滚动条(我尝试滚动条的一些版本在窗口范围之外,即不仅仅是鼠标滚动,而是单击并拖动滚动).
position: absolute;放置在position: relative;父级内部/周围的这些div 从所包含文本的大小和长度接收高度/宽度.
但是,如果其中一个延伸到相对父级的右边界之外,则其宽度似乎会截断.
如何仅使用css使得超出相对父级右侧的div表现为不使用其他父级的div?(应该适用于所有主流浏览器,包括Edge而不是IE)
这是一个小提琴,但我也将复制下面的代码+截图:

HTML:
<div id="relative">
<div id="absolute-working-left">
My width and height are determined by my text content.
</div>
<div id="absolute-working-middle">
Mine, too.
</div>
<div id="absolute-problem">
But not me... I am a problem, because my width is truncated when I extend beyond the right side of my 'relative' parent. WHY???
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
......和风格.请注意,我希望绝对div宽度在包装之前达到最大200px.否则,宽度应由包含文本的长度确定:
#relative {
position: relative;
width: 100px;
height: 100px;
margin-left: 300px;
background-color: white;
}
#absolute-problem,
#absolute-working-left,
#absolute-working-middle {
position: …Run Code Online (Sandbox Code Playgroud) css-position ×10
css ×8
html ×8
position ×3
layout ×2
z-index ×2
android ×1
android-4.0-ice-cream-sandwich ×1
css-tables ×1
iframe ×1
scroll ×1