tags:

views:

74

answers:

5

How can i do this box in css?

it could grow by content..

http://img824.imageshack.us/img824/1953/box.gif

Thanks

A: 

Have a look over here: http://stackoverflow.com/questions/7089/what-is-the-best-way-to-create-rounded-corners-using-css

JochenJung
i dont want to use border-radius prop..
yasink
@JochenJung:- this should be a comment.
Salil
@yasink if you restrict your choices you could end up with image as background. but this could easily achieve by box shodow, gradient , rounded corner css(almost all new broswer support all this). also please mention you do not want to use border-radius property in your question.
iamgopal
A: 

Separate the corners from the rest of the image. The interior (which is colored) should be replaced with transparent background. That way you will have 9 layers. The bottom layer will contain the gradient image repeated, The next 4 layers will contain the top, right, bottom and left border-images with repeat and alignment. The last 4 layers will contain the corners. But using this method the background of this box should be homogeneous (no gradient, no image), otherwise you'd have to place the shadow as a semi-opaque image in PNG, which won't work with rounded corners and border. This won't work with IE6.

Another way is to draw a table, 3x3, with each image. This method will work with IE6 too.

Another way is to stack the 9 divs of the box adjacently, and set the size of the non-content divs using Javascript, by reading the size of the central, content div. This method will as well work with IE6.

All 3 methods provide a possibility to resize the box both vertically and horizontally, using CSS2.

Alexander
9 divs? seriously?
roryf
Some customers I've met are pretty sensitive about using Tables, but do want this kind of stuff to work with dinosaurs like IE6. What other choice do I have?
Alexander
@roryf : unless your box has fixezd width, well yes ...
Felipe Alsacreations
A: 

this will work in firefox. there are similar properties in other browser which can create the same effect. alt text

<div style="-moz-box-shadow: 0 0 2em gray;-moz-border-radius: 5px;border:4px solid white;">
    <div style="-moz-border-radius: 5px;background:-moz-linear-gradient(top,  #ff0,  #fff);">
                aldskfhaklsdhflkashdfklahsdlkfhaklsdhflka <br/>shdflkjhasdklf alksdgh aklsj klsjd<br/>
                aldskfhaklsdhflkashdfklahsdlkfhaklsdhflka <br/>shdflkjhasdklf alksdgh aklsj klsjd<br/>
                aldskfhaklsdhflkashdfklahsdlkfhaklsdhflka <br/>shdflkjhasdklf alksdgh aklsj klsjd<br/>
                aldskfhaklsdhflkashdfklahsdlkfhaklsdhflka <br/>shdflkjhasdklf alksdgh aklsj klsjd<br/>
                aldskfhaklsdhflkashdfklahsdlkfhaklsdhflka shdflkjhasdklf alksdgh aklsj klsjd<br/>
                aldskfhaklsdhflkashdfklahsdlkfhaklsdhflka shdflkjhasdklf alksdgh aklsj klsjd<br/>
    </div>
</div>
iamgopal
A: 

you can make this box with this http://www.456bereastreet.com/lab/transparent_custom_corners_borders/customised.html

will work in all browser.

And with javascript you can get both with this 1) Round corner and 2) Shadow

http://www.ruzee.com/blog/shadedborder

metal-gear-solid
what's wrong with my answer?
metal-gear-solid
I wonder too. R. Johansson used a background image with a width of 1600px and it doesn't display correctly on a 1650px monitor (and 1920px, obviously). Maybe the person that considered your answer wasn't useful thought there was a problem with the method, where there is only a problem with the image or the extreme freedom R. Johansson permitted (I'd constrain max-width to 1280 or 1440px. Only in an example you'll find such width! In real world you have many columns or max-width ...
Felipe Alsacreations
+2  A: 

My suggestion would be to use four divs, and four images:

HTML:

<div id="container">
    <div id="top"></div>
    <div id="content"></div>
    <div id="bottom"></div>
</div>

CSS:

#container { background: transparent url(shadow-repeat.jpg) repeat-y; }
#top { background: transparent url(top.jpg) no-repeat; }
#content { background: white url(gradient.jpg) repeat-x; }
#bottom { background: transparent url(bottom.jpg) no-repeat; }
  • shadow-repeat.jpg is a 1px horizontal slice from the middle (vertically) of the box that includes the white border and the drop shadow
  • top.jpg is tall enough to cover the top rounded corners, and includes the yellow background
  • gradient.jpg is a 1px vertical slice that includes the gradient from the bottom of top.jpg to white
  • bottom.jpg is tall enough to cover the bottom rounded corners, and includes the white background.

The idea is that the container has the white border and the drop shadow on the sides, which repeats vertically, giving you vertical expansion.

The top div has the rounded corners. Since it's a jpg, it will cover the hard corners of the container's background, and positioned correctly, it will still look smooth. The same goes for the bottom div.

The other trick is the horizontally repeated vertical slice of gradient. If the content div is positioned correctly, you can line it up such that it still looks smooth. Since it also has a white background, it will cover any remnants that are left in the middle by the container's repeated background.

This may take a little messing around with margins and positioning to get right, but it's the basic idea

Edit Please note that you will also have to set widths of all divs, and heights of #top and #bottom.

Ryan Kinal
the content gradient may not scale with div vertically, might need resizable background trick like http://css-tricks.com/how-to-resizeable-background-image/
iamgopal
Correct. The gradient itself will not scale. The gradient will go from yellow to white, and any expansion will be white.
Ryan Kinal
It is not necessary to set widths. When using opaque background images, 3 divs are enough. When using opaque background, the divs are better placed one inside another, as layers, not as stacks. Overall this solution has several disadvantages that can be easily avoided.
Alexander
I think, in this particular case, 4 divs is necessary, due to the need to repeat the border and drop shadow, and the gradient.
Ryan Kinal