Tutorial :Transparent and expandable wrapper div, how?


I made an image to easier explain what Im after:

Image Illustration http://bayimg.com/image/eabahaaci.jpg

Ive read some other questions on the subject but Im not sure the solutions will work for me because my div needs to be expandable and grow as more content is added.

Does anyone know how to accomplish this in a simple way?


#body {background: transparent url(background/image.png) 0 0 repeat-y;  }    #content-wrap {width: 60%;                 margin: 0 auto;                 background: transparent url(partially/transparent/60percent-opaque.png) 0 0 repeat;    }    #main-content {width: 90%;                 margin: 1em auto 0 auto;                 background-color: #fff;  }    #footer       {width: 90%;                 margin: 1em auto 0 auto;                 background-color: #fff;  }  

This sets a partially-transparent .png image as the background for the #content-wrap section, with a solid color background for the divs (I've used #main-content and #footer, but they've got the same style so you could just use #content-wrap div and shorten the css a little.

<div id="content-wrap">  <!-- this is the outer wrapping div -->    <div id="main-content">    <!-- this I'm assuming is the main content portion -->    </div>    <div id="footer">    <!-- the name explains my assumption, I think... -->    </div>    </div>  

body {    background: #fff url(http://i.stack.imgur.com/9uIxu.png) 0 0 repeat;  }  #content-wrap {    width: 60%;    margin: 1em auto;    padding: 1em 0;    background-color: rgba(0, 0, 0, 0.3);    -moz-border-radius: 1em;    -webkit-border-radius: 1em;  }  #content-wrap div {    width: 90%;    margin: 1em auto;    background-color: #fff;  }  #content-wrap div p {    margin: 1em 0;  }
<div id="content-wrap">      <div id="main-content">        <p>I presume the main content will sit here...</p>        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium        quis, sem. Nulla consequat massa quis enim.</p>        <p>Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean        vulputate eleifend tellus.</p>        <p>Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue.        Curabitur ullamcorper ultricies nisi.</p>        <p>Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus.        Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit        cursus nunc,</p>      </div>      <div id="footer">        <p>This'd be the footer. And so on...</p>      </div>    </div>

...if you know that your audience will be using FF3.x (and probably webkit based browsers), you could use background-color: rgba(0,0,0, 0.6); to define the background-colour (red=0, green=0, blue=0, alpha=0.4 or 40% opaque (or 60% transparent) -the values being between 0 (entirely transparent) and 1 (entirely opaque).)

Using the rgba for colour prevents problems from using opacity to make the parent div transparent, while trying to make the children visible. But it's got limited use because of browser adoption, of course...

A working demo is over at my site: http://www.davidrhysthomas.co.uk/so/transparent.html


You will need an 1px high image slice for the transperncy and one for the rounded corders at the bottom

.background{      background:url(/image/path);  }  .wrapper{      background:url(/image/path/trans.png) repeat-y;       width:500px;       position:relative;   }  .wrapper .bottom{       background:url(path/to/image) no-repeat;        position:absolute;        bottom:0;        left:0;        height:20px;  }    .inner{      background:#fff;       margin:10px;  }  

I have made the widths and margins up. You should put in the right sizes yourself

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »