Jquery - 带子项(100% 高度和宽度)和动态内容的可调整大小的 DIV

发布于 2024-12-01 02:52:46 字数 1593 浏览 2 评论 0原文

我有一个具有动态内容和调整大小功能的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

╰つ倒转 2024-12-08 02:52:46

没有可用的纯 CSS 跨浏览器解决方案。

现在实现它的唯一方法 - 使用额外的包装器和 display:table + display:table-raw,所以它看起来像这样: http://jsfiddle.net/kizu/UsRuh/28/

问题仍然是:IE。 IE6 和 IE7 无法理解 display 属性的 table 值。

所以克服IE只有两种可能的方法:

  • 使用表达式(但和JS的使用是一样的)
  • 使用无语义的表格而不是div,这样它在任何地方都可以工作。

这确实是一个大问题,并且表格布局在很长一段时间内是唯一可能的解决方案。然而,在未来(现在在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 the display property.

So there are only two possible ways to overcome IE:

  • use expressions (but it's the same as the use of JS)
  • use unsemantic table instead of divs, so it would work everywhere.

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.

酒几许 2024-12-08 02:52:46

如果您只有一个 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 parent div (#main) has relative or absolute positioning.

成熟稳重的好男人 2024-12-08 02:52:46

我对 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文