Jquery - 带子项(100% 高度和宽度)和动态内容的可调整大小的 DIV
我有一个具有动态内容和调整大小功能的 DIV。
这是一个例子-> http://jsfiddle.net/UsRuh/4/
问题在于动态内容。
示例-> http://jsfiddle.net/UsRuh/5/
它只有在我设置时才有效#main
DIV 上方的填充。
示例-> http://jsfiddle.net/UsRuh/6/
是否可以(仅使用 CSS,不使用 JS!)解决这个问题?
CSS
#header {
background-color:#faf; }
#main {
position: absolute; top: 18px; left: 18px; width: 384px; height: 157px;
padding:0px 0px 80px 0px;
position: absolute;
overflow:hidden;}
#scrollDiv {
background-color:#ccaacc;
height: 100%;
overflow-y: scroll;
overflow-x: hidden;
padding-right: 25px;
width: 100%; }
HTML
<div id="main">
<div id="header">Head</div>
<div style="background-color:#555;"> some dynamic content text text text text <br /> some dynamic content</div>
<div id="scrollDiv"> some dynamic content width "invisible" scroll<br />text text text text text text text text text text text text text text text text text text text text text text text text text text text text .... ext text </div>
<div style="background-color:#555;"> some dynamic content text text text text <br /> some dynamic content</div>
</div>
编辑: 如果没有其他解决方案,请告诉我。
i have a DIV with dynamic content and resize function.
Here is an example -> http://jsfiddle.net/UsRuh/4/
The problem is the dynamic content.
Example -> http://jsfiddle.net/UsRuh/5/
It will only work when i set the padding from the #main
DIV higher.
Example -> http://jsfiddle.net/UsRuh/6/
Is it possible (only with CSS, no JS!) to resolve this problem?
CSS
#header {
background-color:#faf; }
#main {
position: absolute; top: 18px; left: 18px; width: 384px; height: 157px;
padding:0px 0px 80px 0px;
position: absolute;
overflow:hidden;}
#scrollDiv {
background-color:#ccaacc;
height: 100%;
overflow-y: scroll;
overflow-x: hidden;
padding-right: 25px;
width: 100%; }
HTML
<div id="main">
<div id="header">Head</div>
<div style="background-color:#555;"> some dynamic content text text text text <br /> some dynamic content</div>
<div id="scrollDiv"> some dynamic content width "invisible" scroll<br />text text text text text text text text text text text text text text text text text text text text text text text text text text text text .... ext text </div>
<div style="background-color:#555;"> some dynamic content text text text text <br /> some dynamic content</div>
</div>
EDIT:
If no other solution exists, please tell me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有可用的纯 CSS 跨浏览器解决方案。
现在实现它的唯一方法 - 使用额外的包装器和
display:table
+display:table-raw
,所以它看起来像这样: http://jsfiddle.net/kizu/UsRuh/28/问题仍然是:IE。 IE6 和 IE7 无法理解
display
属性的table
值。所以克服IE只有两种可能的方法:
这确实是一个大问题,并且表格布局在很长一段时间内是唯一可能的解决方案。然而,在未来(现在在webkit和firefox中)我们可以尝试使用灵活的盒子模型。
借助灵活的盒子模型,只需使用 CSS 即可轻松实现您想要的目标: http://jsfiddle.net/ kizu/UsRuh/29/
这就是灵活盒模型出现的原因。太遗憾了,它的可用性仍然不完美。
There are no CSS-only crossbrowser solutions available.
The only way to achieve it now — to use extra wrappers and
display:table
+display:table-raw
, so it would look like that: http://jsfiddle.net/kizu/UsRuh/28/The problem still: IE. IE6 and IE7 won't understand
table
values of thedisplay
property.So there are only two possible ways to overcome IE:
That's really a big problem and table layout was the only posible solution for a long time. However, in the future (and now in webkit and firefox) we can try to use the flexible box model.
With flexible box model it's realy easy to achieve what you want only with CSS: http://jsfiddle.net/kizu/UsRuh/29/
And that's why the flexible box model appeared. Too sad, it's availability is still not perfect.
如果您只有一个
div
在可滚动 div 下方包含动态内容,则可以使用绝对定位将其捕捉到底部。只需确保父级div
(#main
) 具有相对或绝对定位即可。If you have only one
div
with dynamic content below scrollable div you make it snap to bottom with absolute positioning. Just make sure parentdiv
(#main
) has relative or absolute positioning.我对 CSS 做了轻微的更改,可以在以下位置看到: http://jsfiddle.net/KuzTB/
我已经包含了 CSS3 的伪类:nth-child(n) 并将其应用于最后一个内部 div。
I have made a slight change in CSS and can be seen at: http://jsfiddle.net/KuzTB/
I have included a pseudo-class of CSS3: nth-child(n) and applied it on last inner div.