1

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?

mdc
  • 1,161
  • 6
  • 22
  • 37

2 Answers2

2
#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(https://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

David Thomas
  • 249,100
  • 51
  • 377
  • 410
  • What about the rounded corners at the bottom of the wrapper? – Cato Johnston Jun 23 '09 at 23:52
  • Do you just want the rounded corners on the bottom of the wrapper? – David Thomas Jun 23 '09 at 23:59
  • Thanks to both of you, you answered my question. This is the solution I thought would work but wasn't sure. BTW, is there an "optimal" size of the image that I will make transparent (and repeat as background)? I mean is it slower to load a 1x1px image? (Because it has to be repeated many more times than, say a 10x10px image) Maybe the performance difference is so small that it doesn't matter? Thanks again for the answer. – mdc Jun 24 '09 at 03:49
  • The optimal image size is a balance between ensuring it's easy to download (small file size, optimized and so on), and large enough to avoid the browser slowing down while it repeats the image. My inclination would be an image of around 20 * 20px, but there's no absolute 'right' answer. – David Thomas Jun 24 '09 at 12:50
0

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

Cato Johnston
  • 44,131
  • 10
  • 39
  • 42