CSS:另一个绝对DIV内的绝对DIV
我有以下内容:
<style type="text/css">
div.container
{
width: 100px;
height: 300px;
border: solid 1px #CCCCCC;
position: absolute;
top: 20px; /* Will change depending on where the box is opened */
left: 20px; /* Same */
overflow: hidden;
}
div.block
{ /* Will exceed 300px in height */
width: 100px;
position: absolute;
top: 0px;
left: 0px;
}
</style>
[...]
<div class="container">
<div class="block">
<!-- hyperlinks -->
</div>
</div>
我正在尝试创建一些模仿滚动的东西 - 一个在盒子内移动的盒子。 IE 做得很好; “块”div
完美隐藏在“容器”div
内。所有其他浏览器都会在页面顶部、“容器”div
上方抛出“块”div
,并相对于页面进行定位。
我怎样才能让其他人像 IE 一样行事?
I have the following:
<style type="text/css">
div.container
{
width: 100px;
height: 300px;
border: solid 1px #CCCCCC;
position: absolute;
top: 20px; /* Will change depending on where the box is opened */
left: 20px; /* Same */
overflow: hidden;
}
div.block
{ /* Will exceed 300px in height */
width: 100px;
position: absolute;
top: 0px;
left: 0px;
}
</style>
[...]
<div class="container">
<div class="block">
<!-- hyperlinks -->
</div>
</div>
I'm trying to create something that imitates scrolling - a box that moves around within a box. IE does this beautifully; the 'block' div
is perfectly hidden within the 'container' div
. Every other browser throws the 'block' div
at the top of the page, above the 'container' div
and positioning relative to the page.
How do I get everyone else to behave like IE does?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的第一个
div
应具有固定的宽度和高度,并具有 CSS 属性overflow: auto;
。此div
内任何大于它的内容都会导致父 div 显示滚动条。然后,您可以随意将其
位置
设置为绝对
,并将其放置在您喜欢的任何位置。演示:http://jsfiddle.net/duc44/
Your first
div
should have a fixed width and height, with the CSS propertyoverflow: auto;
. Anything inside of thisdiv
that's larger than it will cause the parent div to display scrollbars.You're then free to set it to
position
toabsolute
, and place it anywhere you like.Demo: http://jsfiddle.net/duc44/