0

I have some containers in the page like this:

<div id="con1" class="window">
    <div>xxxx</div>
    <div>xxxx</div>
</div>

<div id="con2" class="window">
    <div>xxxx</div>
    <div>xxxx</div>
</div>

And an image like this:

enter image description here

Now,I want to make the image as the background of the containers to make the containers look like a window. Like this:

enter image description here

Also,the size of the containers may changed according to user. So I want it can auto expand when the content of the containers added.

Any idea?


update:

What I have tried yet:

9 divs layout

And this is what I get now: jsfiddle

hguser
  • 35,079
  • 54
  • 159
  • 293
  • I have tried to create 9 divs with absolute position one by one,and three in each row(three rows totally)(see image I updated). And set the backgound for the divs expect the div at the middle. Now,it works,but the container can not change its size according to the content. – hguser Jan 08 '13 at 11:26
  • See my update. I update it. – hguser Jan 08 '13 at 12:38

2 Answers2

1

EDIT:

Solution n.2:

you could even use two divs, one "outer" with the gradient background, the optional shadow, and the rounded borders, and one "inner" with white background containing your stuff.

Demo: http://jsfiddle.net/TqutW/4/

HTML

<div class="windowBorder" >
    <div class="windowContent" >
       <div >xxxxxxxxxxxxxxx</div>
       <div >xxxxxxxxxxxxxxx</div>
       <div >xxxxxxxxxxxxxxx</div>
       <div >xxxxxxxxxxxxxxx</div>                          
    </div>        
</div>

CSS (crossbrowser)

.windowBorder{
  margin: 30px;  
  padding: 20px 8px 8px 8px;  
  box-shadow: 2px 2px 5px 1px #111111;
  border-radius: 10px;
background: #7d7e7d; /* Old browsers */
background: -moz-linear-gradient(top, #7d7e7d 0%, #0e0e0e 13%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#7d7e7d), color-stop(13%,#0e0e0e)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #7d7e7d 0%,#0e0e0e 13%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #7d7e7d 0%,#0e0e0e 13%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #7d7e7d 0%,#0e0e0e 13%); /* IE10+ */
background: linear-gradient(to bottom, #7d7e7d 0%,#0e0e0e 13%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#7d7e7d', endColorstr='#0e0e0e',GradientType=0 ); /* IE6-9 */
}

.windowContent {    
   padding: 10px;
   background-color: white;   
}

You only need to create the div(s) around your content via javascript...


Solution n. 1

You don't really need to use images for this.

(you would need to use images, for example, with a "wood" border, then you should do it in the old-school way... an image for every angle, one image for the vertical line, one for the horizontal line, and a lot of divs...)

All you have here is a gradient (achievable using CSS3 Gradients) and rounded borders (achiaveble using CSS3 border-radius). You can add shadow too with CSS3 box-shadow...

Gradients are easily generated with the CSS3 Gradient Generator, but today they're cross-browser for BACKGROUND attribute only... you can use gradient on BORDERS in webkit browsers, not yet in FF nor IE... but you can add a div as the header of the window, with a gradient background.

This is a fiddle for wrap content inside a window with rounded border and shadow (with no gradients):

http://jsfiddle.net/TqutW/3/

And the only javascript needed is the one that applies the new class to the container div... enjoy.

HTML

   <div id="container1">            
        <div >xxxxxxxxxxxxxxx</div>
        <div >xxxxxxxxxxxxxxx</div>
        <div >xxxxxxxxxxxxxxx</div>
        <div >xxxxxxxxxxxxxxx</div>
   </div>
   <br/>
   <input type="button" id="click"  value="windowization! :)"/>

CSS

.window{    
  margin: 30px;
  padding: 10px;
  border-style: solid;  
  border-width: 20px 8px 8px 8px;
  border-color: #444;
  border-radius: 10px;
  box-shadow: 2px 2px 10px 1px #111111;
}

JS

document.getElementById("click").onclick=function(){
   document.getElementById("container1").className+=" window ";
}
Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • awesome! However how about if I want to make the same effect cross browser(ie7 and ie7+ and ff,chrome)? – hguser Jan 08 '13 at 13:38
  • Both solutions are crossbrowsers ! The only thing not crossbrowser WOULD BE gradient borders, with only one div... and i did not included that :) If you look at Solution n.2, all that bunch of (commented) code for background gradient is generated by the linked CSS3 Gradient Generator to be crossbrowser to IE6 :) look at the end of the comment in CSS part for the name of the browser that will read that declaration – Andrea Ligios Jan 08 '13 at 13:46
  • Thank you very much! Then how about if I want to use some background-image which can not implemented by the css3 like `http://imagebin.org/242132`? It seems that the only solution is the old-school way? – hguser Jan 08 '13 at 14:20
  • No, i forgot to specify that with Solution n.2 you can use an background-image as well... just change the "background" part, removing the gradient and adding the image. Please consider that the image you posted in the comment is totally different from the one in the question... the one in the question is a gradient window, the one in the comment is a tooltip, with no gradient but with an arrow... they're generally handled differently – Andrea Ligios Jan 08 '13 at 14:30
  • Take a look at how to create triangles outside one object with CSS only, without even having the tooltip image: http://stackoverflow.com/a/13273672/1654265 – Andrea Ligios Jan 08 '13 at 14:31
  • I am afraid the solution is not cross browser,since I have test it in IE8,and I found ie8 does not support the border-radius style. – hguser Jan 09 '13 at 00:10
  • Andrea Ligios:Like you side,if I want to use the image posted in the comment,then does that mean that I have to use the old-school way? – hguser Jan 09 '13 at 05:48
  • This could be a separate question i guess... create a resizable tooltip is easier but different than creating a resizable (*gradiented*) window around your content... If you'll ask that, I'll answer there, otherwise i'll give you here some advices: create an image with only the bottom part of your tooltip; create a class with the background-image positioned centered on BOTTOM, with a bottom margin and with the border-top, -left and -right of the same color of the image... something like that :) – Andrea Ligios Jan 09 '13 at 10:35
0

Try the fiddle, http://jsfiddle.net/siyakunde/TqutW/1/ Is this what you are trying to do?

#content{
  background-image: url('http://www.google.com/images/srpr/logo3w.png');
  background-size: 100% 100%;
}
I29
  • 686
  • 4
  • 9