如何在隐藏身体溢出的同时更改单个元素的溢出?

时间:2011-09-14 00:41:42

标签: html css overflow frame

下面的html基本上应该是左边垂直对齐的图像列表。我希望图片滚动,但我不希望页面的其余部分滚动。我还希望页面的其余部分有一个隐藏的溢出。无论如何只用html和css以及如何做到这一点?

HTML:

<!DOCTYPE html>
<html>
<title>Scrolling Pictures</title>
<head>
<link rel="stylesheet" type="text/css" href="scrollingPictures.css" />
</head>
<body>
<div id="scroll">
<img class="left" id="image1" src="C:\Users\Shikamaru\Documents\Contwined Coding\Ravel\New Briefcase\images\bradBeachHeart.JPG" alt="Brad at the Lake"/>

<img class="left" id="image2" src="C:\Users\Shikamaru\Documents\Contwined Coding\Ravel\New Briefcase\images\mariaNavi.jpg" alt="Making Maria Na'vi"/>

<img class="left" id="image3" src="C:\Users\Shikamaru\Documents\Contwined Coding\Ravel\New Briefcase\images\mattWaterRun.jpg" alt="Photoshopped Matt"/>
</div>
</body>
</html>

CSS:

body{
overflow:auto;
margin-left:0;
margin-top:0;
}
div#scroll{
border-right:1px solid orange;
position:absolute;
z-index:2;
float:left;
width:200px;
overflow:auto;
}
.left{
z-index:inherit;
float:left;
width:200px; 
min-height:200px; /* for modern browsers */
height:auto !important; /* for modern browsers */
height:200px; /* for IE5.x and IE6 */
opacity:0.4;
filter:alpha(opacity=40);
}
#image1, #image2, #image3{
width:200px;
}

1 个答案:

答案 0 :(得分:1)

只需将#scroll的高度设为100%,将body设为overflow: hidden

body{
    overflow:hidden;
    margin-left:0;
    margin-top:0;
}
div#scroll{
    border-right:1px solid orange;
    position:absolute;
    z-index:2;
    float:left;
    width:200px;
    overflow:auto;
    height: 100%;
}
.left{
    z-index:inherit;
    float:left;
    width:200px; 
    min-height:200px; /* for modern browsers */
    height:auto !important; /* for modern browsers */
    height:200px; /* for IE5.x and IE6 */
    opacity:0.4;
    filter:alpha(opacity=40);
}
#image1, #image2, #image3{
    width:200px;
}

http://jsfiddle.net/QcHNu/