...

View Full Version : scroll div with transparent background, how?



Bubbel
12-13-2010, 11:14 AM
Hello!

I have put a transparent background on one of my divs and got the text to show on top of that background.

But on one of the pages the text is too long so I put a scrolling effect on it, but then the background doesn't show under the whole text, its just follows the scrolling. How do I fix that?

Here is the code of the div:


<div id="main" class="container">

<div class="centerBlock"></div>
<div class="text">

// A lot of text!

</div>
</div>

And here is the css code for that div:

#main {
position:absolute;
width:475px;
height:680px;
margin-left:170px;
top:190px;
overflow: auto;
overflow-x:hidden;
}

.centerBlock {
position:absolute;
top:0;
bottom:0;
background-color:#FFFFFF;
filter:alpha(opacity=60);
opacity:0.6;
width:460px;
height:680px;

}

#main .text {
width:445px;
height:auto;
padding-left: 6px;
}

.text {
position:relative;
font-size: 90%;
}

yakoup46
12-13-2010, 06:31 PM
Well if the text field is going to be static just change the height of the .centerBlock div to that specific height. But first you have to fix your div wrapping. You have....

<div id="main" class="container">

<div class="centerBlock"></div>
<div class="text">

// A lot of text!

</div>
</div>

Should be...

<div id="main" class="container">

<div class="centerBlock"></div>-delete this tag and put where bold one is
<div class="text">

// A lot of text!

</div>
</div>
</div>

Bubbel
12-13-2010, 09:14 PM
I cant move that </div> tag because then the text also gets transparent...

If i change the height of .centerBlock nothing happens, and nothing happens when I change the height of the #main .text ether...

Any other suggestions?

yakoup46
12-13-2010, 09:27 PM
Oh right I didn't even look at the text transparency. Let me have another look real quick.

yakoup46
12-13-2010, 09:33 PM
What browser are you having this problem in? Because simply changing the div height works for me.

Excavator
12-14-2010, 12:49 AM
Hello Bubbel,
Since your .text is higher than it's containing #main, 100% height doesn't work. You see 100% of the height of #main and then scrolling takes you past that.

Instead, try giving .text a height tall enough to contain whatever you put in it.
Like this -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html, body {
margin: 0;
background: #f63;
font: 100% "Trebuchet MS", Arial, Helvetica, sans-serif;
color: #333;
}
#main {
height: 680px;
width: 475px;
margin: 50px 0 50px 50px;
position: relative;
overflow: auto;
}
.centerBlock {
height: 1200px;
width: 100%;
margin: 0px;
position: absolute;
top: 0;
left: 0;
z-index: 1;
background: #fff;
filter: alpha(opacity=60);
opacity: 0.6;
}
#main .text {
width: 445px;
padding-left: 6px;
position: relative;
top: 0;
left: 0;
z-index: 2;
font-size: 90%;
}
</style>
</head>
<body>
<div id="main" class="container">
<div class="centerBlock"></div>
<div class="text">
<p>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
<br /><br /><br /><br /><br /><br />
aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
<br /><br /><br /><br /><br /><br />
sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
<br /><br /><br /><br /><br /><br />
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo
<br /><br /><br /><br /><br /><br />
duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
<br /><br /><br /><br /><br /><br />
aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
<br /><br /><br /><br /><br /><br />
sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
<br /><br /><br /><br /><br /><br />
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo
<br /><br /><br /><br /><br /><br />
duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
<br /><br /><br /><br /><br /><br />
This is the last sentence.
</p>
</div>
</div>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum