自动高度div溢出和需要时滚动 [英] Auto height div with overflow and scroll when needed

查看:147
本文介绍了自动高度div溢出和需要时滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个网站没有垂直滚动的页面,但我需要一个DIV我必须垂直扩展到页面的底部(最多),并且当它有内容不适合,div应该创建一个垂直滚动。



我已经有 href =http://jsfiddle.net/CdN7L/92/>这个小提琴,在需要时创建滚轮。我也想出了如何使容器div增长,以占据完全垂直的空间,它在页面中。我只是不能让他们一起工作!



请记住,在jsfiddle你将无法查看整个网站的内容,感觉你得到的第二个小提琴不真正显示正在做什么,但它的工作原理虽然。



只是另一个注释:因为他们是不同的fiddles,第一个小提琴的id#container div是第二个例子的id#dcontent div。



还有一件事:对于一种内容,这个div垂直滚动,但对于其他类型的内容,我想要它水平滚动,因为它将有一个产品滑块显示元素水平在此DIV。



看看这张照片,因为它可能更容易理解我想说什么:图片



我试图寻找关于这些主题的其他问题,但没有一个似乎涵盖了我想解决的所有方面...:S



如果有其他我可以提供帮助你/我:)计算出来,请让我知道!



谢谢! b
$ b

EDIT1:固定拼写错误



EDIT2:添加图片以解释

解决方案

好吧,经过长时间的研究,我发现一个解决方法,我需要:
http://jsfiddle.net/CqB3d/25/



CSS:

  body {
margin:0;
padding:0;
border:0;
overflow:hidden;
height:100%;
max-height:100%;
}

#caixa {
width:800px;
margin-left:auto;
margin-right:auto;
}
#framecontentTop,#framecontentBottom {
position:absolute;
top:0;
width:800px;
height:100px; / *顶框div的高度* /
overflow:hidden; / *禁用滚动条。设置为滚动以启用* /
background-color:navy;
color:white;
}

#framecontentBottom {
top:auto;
bottom:0;
height:110px; / *底部框架高度* /
overflow:hidden; / *禁用滚动条。设置为滚动以启用* /
background-color:navy;
color:white;
}

#maincontent {
position:fixed;
top:100px; / *将顶值设置为HeightOfTopFrameDiv * /
margin-left:auto;
margin-right:auto;
bottom:110px; / *将底值设置为HeightOfBottomFrameDiv * /
overflow:auto;
background:#fff;
width:800px;
}

.innertube {
margin:15px; / * IE6 hack * /
padding:130px 0 110px 0; / *每个DIV内部DIV的边距(以提供填充)* /
}

* / *设置值为(HeightOfTopFrameDiv 0 HeightOfBottomFrameDiv 0)* /
}

* html #maincontent {/ * IE6 hack * /
height:100%;
width:800px;
}

HTML:

 < div id =framecontentBottom> 
< div class =innertube>

< h3>此处的示例文字< / h3>

< / div>
< / div>


< div id =maincontent>
< div class =innertube>

Lorem ipsum dolor sit amet,consectetur adipiscing elit。 Sed scelerisque,ligula hendrerit euismod auctor,diam nunc sollicitudin nibh,id luctus eros nibh porta tellus。雪松匍匐。 Quisque在mi dolor,eu fermentum turpis。 Nunc posuere venenatis est,in sagittis nulla consectetur eget ... // longer longer text ...
< / div>
< / div>
< / div>

可能不适用于水平的东西,但它是一个正在进行的工作!

我基本上放弃了inception盒子 - 盒子里面的盒子模型,并使用动态高度和溢出属性的固定定位。



希望这可能有助于稍后找到问题的人。



编辑:这是最后的答案。


I'm trying to make a website with no vertical scrolling for a page, but i need that one of the DIVs i have to expand vertically to the bottom of the page (at most), and that when it has content that does not fit, the div should create a vertical scroller.

i already have the css for the inside of the div figured out in this fiddle, creating the scroller when needed. i also have figured out how to make the container div grow to occupy exactly the vertical space it has in the page. i just can't make them work out together!

please have in mind that in jsfiddle you won't be able to view the content of the whole website and in that sense what you get for the 2nd fiddle doesn't really show what's being done, but it works as i intended though.

just another note: as they are different fiddles, the id#container div in the 1st fiddle is he id#dcontent div of the 2nd example.

there is one other thing: for a type of content, this div will scroll vertically, but for other type of content, i want it to scroll horizontally, as it will have a product "slider" displaying elements horizontally inside this DIV.

please also look at this photo because it might be easier to understand what i'm trying to say: PICTURE

i tried looking to other questions regarding these topics, but none seemed to cover all of the aspects i'm trying to solve... :S

if there is something else i can provide to help you/me :) figuring it out, pls let me know!

thanks!

EDIT1: fixed typos

EDIT2: added picture for explanation

解决方案

Well, after long research, i found a workaround that does what i need: http://jsfiddle.net/CqB3d/25/

CSS:

body{
margin: 0;
padding: 0;
border: 0;
overflow: hidden;
height: 100%; 
max-height: 100%; 
}

#caixa{
    width: 800px;
    margin-left: auto;
    margin-right: auto;
}
#framecontentTop, #framecontentBottom{
position: absolute; 
top: 0;   
width: 800px; 
height: 100px; /*Height of top frame div*/
overflow: hidden; /*Disable scrollbars. Set to "scroll" to enable*/
background-color: navy;
color: white; 
}

#framecontentBottom{
top: auto;
bottom: 0; 
height: 110px; /*Height of bottom frame div*/
overflow: hidden; /*Disable scrollbars. Set to "scroll" to enable*/
background-color: navy;
color: white;
}

#maincontent{
position: fixed; 
top: 100px; /*Set top value to HeightOfTopFrameDiv*/
margin-left:auto;
    margin-right: auto;
bottom: 110px; /*Set bottom value to HeightOfBottomFrameDiv*/
overflow: auto; 
background: #fff;
    width: 800px;
}

.innertube{
margin: 15px; /*Margins for inner DIV inside each DIV (to provide padding)*/
}

* html body{ /*IE6 hack*/
padding: 130px 0 110px 0; /*Set value to (HeightOfTopFrameDiv 0 HeightOfBottomFrameDiv 0)*/
}

* html #maincontent{ /*IE6 hack*/
height: 100%; 
width: 800px; 
}

HTML:

<div id="framecontentBottom">
<div class="innertube">

<h3>Sample text here</h3>

</div>
</div>


<div id="maincontent">
<div class="innertube">

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed scelerisque, ligula hendrerit euismod auctor, diam nunc sollicitudin nibh, id luctus eros nibh porta tellus. Phasellus sed suscipit dolor. Quisque at mi dolor, eu fermentum turpis. Nunc posuere venenatis est, in sagittis nulla consectetur eget... //much longer text...
</div>
</div>
</div>

might not work with the horizontal thingy yet, but, it's a work in progress!

I basically dropped the "inception" boxes-inside-boxes-inside-boxes model and used fixed positioning with dynamic height and overflow properties.

Hope this might help whoever finds the question later!

EDIT: This is the final answer.

这篇关于自动高度div溢出和需要时滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆