Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question scroll div with transparent background, how?

    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:

    Code:
    <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:
    Code:
    #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%;
    }

  • #2
    New Coder
    Join Date
    Apr 2010
    Posts
    28
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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>

  • #3
    New Coder
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    New Coder
    Join Date
    Apr 2010
    Posts
    28
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Oh right I didn't even look at the text transparency. Let me have another look real quick.

  • #5
    New Coder
    Join Date
    Apr 2010
    Posts
    28
    Thanks
    0
    Thanked 3 Times in 3 Posts
    What browser are you having this problem in? Because simply changing the div height works for me.

  • #6
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    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 -
    Code:
    <!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>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •