Simple Box by tedd
Note: this is a box with rounded corners. I have reviewed the available references and found similar solutions, but none that do it this way.
✓ This box was created by using eight very small gifs. One for each corner, and one for each side (total combined size of only 7.2 KB).
✓ This box automatically resizes height depending upon content. The width can be tied to the size of the viewport or set to a fixed size by changing the width value.
✓ This box can be made any size without any problems with graphics. In other words, you don't have to create a large graphic for this box to accommodate extra large sizes.
✓ This box is not affected by changes in text-zoom and holds its shape throughout all magnifications.
✓ The only known browsers that have problems with this technique are: Netscape 4.78 for Windows 2000, Netscape 4.8 for Linux, and Internet Explorer 4.0 for Window's 98.
✓ This box technique Validates under "HTML 4.01 Strict" and "W3C CSS".
✓ The technique looks fine (i.e., readable) without CSS.
✓ Here are the GIF's for the borders
Please donate $5 below for my development effort -- thank you.
This technique W3C validates under both HTML 4.01 Strict and CSS guidlines.
Enjoy.
tedd...
Comments
Thanks :)
Please, do more tips and hints for us!!
I've been looking at your site and I think it just brilliant! I'd just like to say thanks for the tutorials and tips which you have explained so clearly and made easy for beginners like myself.
Cheers,
Neil.
Interesting and confusing comments. I'm not sure what CRUFTY means, but it doesn't sound good.
As for my div's being not semantic, how semantic does a border have to be?
As for changing the design, you can change this to whatever you want. However, if you want rounded corners, then this is one way to do it.
As for using HTML that's already prepared for it, I have no clue as to what you are talking about. The process simply creates a page with rounded corners. If you want rounded corners, then it works. If you don't want rounded corners, then don't use it.
If you think it is limited to a very rare set of HTML, then you are wrong -- check this out:
http://webbytedd.com
There you will find dozens of pages using the technique -- and I have dozens more.
tedd
I made last week a complete restyling of my site. I used this example for the layout. Now I saw that all your site is made equal.. if it's a problema, this evening I'll change the rounded corner template.
Great job
Nunzio Fiore
http://www.moonkiki.com
I'm not sure what you mean by "all your site is made equal" -- please explain.
tedd
Please let me know if I'm missing something. I have tried every manner of CSS to try to fix the problem. If only I could dictate where the side image started and shift that by a few pixels, I would be ok.
David
The problem isn't with the technique, but with the images and the way browsers display those images. The technique just places the images where they should go.
In other words, work on the images.
tedd
I really like your rounded corner approach. My question is, how do you create those graphics? Pixel by pixel, or with some tool that makes it easy? I would love to try your technique but play around with different graphic components. If you have any recommendations on how to build them, I'd be quite grateful...
Paul
That's the fly in this ointment -- for the technique to work, you need to create eight graphics to cover all the edges. What I've provided here works for a foreground color of #eeeeee and background color of white. But that's pretty limited. So to use this, it would be nice to have a system to create these images "as needed". I've thought about creating a program that would do that, but just don't have the time.
In any event, as I remember, I used Photoshop to create the images by first determining what background and foreground I needed. I then took my current image and removed the color (shades of gray) and then pasted it on the background with anti-aliasing on. After that I added in the foreground and just kept changing things until I got it the way I wanted -- it's a labor intensive process -- no real method.
tedd
It can shrink or grow depending on the content so i never have to worry about breaking.
Is it possible to change the background color, I have tried but it doesnt seem to be working?
john
http://www.webmasterclip.com/story/simple-rounded-box-sample
How come I can't get it too work? I'm a amateur at this web design thing. I'm only a newbie student learning Web Design (hoping to become a good website designer in the future) in college, and I was wondering if you can help me out. I tried saving the two files from .html, and .css on my desktop (including the images).
I post the code on my Coda/TextEdit, and tried it out, but it didn't seem to work. Please help me. Thanks.
As an amateur, then this project will be a good start to figure out how it works. It is a *really* simple example of how one can use css and html. You don't need any help, just look at what I have provided.
tedd
I know you call it a simple box, but it is still a great simple box and does everything I need.
I guess I could change color via Photoshop? Will give it a go.
Thanks though.
David
When I state that it's been tested in ALL known browsers and only fails for the most ancient Netscape 4 and IE 4, which absolutely no one uses any longer, that's what I mean.
When you visit this page in FireFox, does it work? If not, please tell me what version of FireFox and what operating system you are using.
tedd
I have a very weird problem and I don't have any clue about how to solve it.. I've tried many things already perhaps somebody can give me a hint about where to look.
I've changed the graphics and the border works perfectly in Firefox and also in Explorer 7 when I first load it. However, when I scroll down the page in IE 7 to the point that the upper border is no more visible and then scroll back to see the border again, the upper border and corners are not visible any more until I reload the page... any clue?
Thanks very much.
My example shows a single page and outlines that page with the images that makeup the rounded corners. If you want to have more than one box per page, then just repeat the html code accordingly.
Cheers,
tedd
I had that problem when IE7 first came out, but I fixed it with the css rule of:
#tlc, #trc [ zoom: 1]
That line is included in the css for this demo. Check your code to make sure that line is there.
Also check my site with your IE7 and see if the problem is there. When I test it in IE7, I see no problems whatsoever.
Cheers,
tedd
Sometimes, thanks makes it all worthwhile.
Cheers,
tedd
Cool technique. One improvement that jumped to mind would be to combine all of the images back into 1, and then use CSS 'image sprites' to just use the chunk of the image you need at any one time. This would greatly reduce the traffic from 8 images to 1.
HTH,
Jim
Go ahead and do that -- that could be your contribution to the collective.
Cheers,
tedd
In Firefox if we have a long text ,the table is not growing.It just come out of the box.Any solution for that?
Thanks,
Sree
I reviewed the web site you provided in your link. The problem I see is that you are using id's and not classes. In css, you can use a class as many times as you want, but id's can be used only once per page.
You should change your id's to classes and try again.
Cheers,
tedd
I created a box from your model. My box has a thinner border and can have any color background.
I have the 8 GIF's and the HTML & CSS codes if you want to offer it to people who use your box.
The one negative to your box (if their can be one for something free) was it had to be grey or the border didn't match.
You can see the boxes in the right column of my web page. Let me know!
I have one problem.
If content in the box is one below the other the box itself rizes the height and all fits together. If content is side by side, what i normally do with divs and float: left, the box-background stops its height and the side-by-side content will be positioned outside the box, underneath. I can catch this when I gave an value to box height, but I need it for a dynamic solution (CMS) and this means that I cannot know an each page, which value is needed?
On this page (here) I found, that your classes quote and text are side-by-side. In my example they would lay underneath the grey area. I can't see, how you did that?
thanks in advance
Deniz
This is simply a box with rounded corners. If you want to expand this to include other things, then fine but that's beyond what I am presenting.
As far as how I did this, just look at the code. You will find it's a simple box with everything included within it.
Cheers,
tedd
You made my day. I was working through the excellent Css Missing Manual and I noticed a reference to your website and I now want to use your box for my website.
Brian
Cheers.
tedd
The problem that you are experiencing has nothing to do with css. The problem is that the images you are using to go from one area to another, a transition, is suffering from anti-aliasing problems.
Solution -- create two images, namely the main center and the surrounding outer. Use whatever colors you want for both areas. Then create a transition zone from one area to the other area via eight different edges, namely top-edge, top-edge-right, top-edge-left, left-edge, right-edge, bottom-edge, bottom-edge-right and bottom-edge-left. Once you have created those eight images, then simply replace mine with those.
Good luck,
tedd
I have a problem (http://i239.photobucket.com/albums/ff59/88madde/boxsample.jpg) image repeat.
I use the same code like you but changed the images in photoshop, i changed white to transparent.
Is there any way to correct this?
thanks
on my website the background color is not white so if i try to put this rounded box, it show's extra space with white color on top and right side. how can i get rid of this space or how can i change white color to my background color ??
Thanks
Amanda
Please read previous before asking a question that has been answered.
Thanks,
tedd
No clue -- I always roll my own. That way I have only myself to blame when things don't work right. But on the other hand, I usually can fix any problems I encounter.
Cheers,
tedd
To make a rounded-corner box I create an image with rounded corners in Photoshop about 200 x 200 pixels with the rounded corners tool (similar to the box tool, but the corner radius can be specified), then slice the image into 8 pieces - I don't use the blank in the middle, obviously!
I set all my colours and transparency right here, and save the file as a master so I can come back and re-invent the wheel through my own time-warp!!
Then I create a table with 3 columns and 3 rows at the (table) width I desire - I usually use 760 pixels. Each corner cell uses one of the corners from the sliced image, then I insert bottom and top, left and right side images appropriately.
Each side image gets it's actual width specified (40, for example) but 100% on the height, top and bottom get their actual height specified (40 again, for example) but 100% on the width. The sides and top/bottom images stretch to fill the gaps. The only drawback is if you have a textured image frame, then you make the original as long as possible or it tends to look streaked as it stretches.
An alternative is to make the sides and top/bottom a repeating background image, but that;s only necessary if you don't want to stretch the image for some reason.
Then I tailor the dimensions of the cells ringing the middle to the width of the cells and the height of top and bottom, leaving the middle with no dimensions specified.
Make this page the master, then fill with whatever you have... it resizes (vertically) to hold whatever you drop in.
BTW, this process uses the same image set used here with CSS - the frame pieces of a rounded-corner box image - I'm just using an HTML table to draw it all together instead of CSS.
Hope that helps someone...
One of the main "rules" in css is not to use tables for anything other than column data. You are violating that rule and there is no reason for doing so.
Using div's as I have done here is easy to understand and implement -- plus it resizes both vertically and horizontally to hold what ever you drop in.
Instead of adding a table, it's far better to use simple div's to accomplish this effect.
Cheers,
tedd
Brilliant!
Thank You very much Tedd.
:-)
-Govinda
You may use this technique for anything you want without any obligation to me whatsoever. If you want to donate to help with site expense, please use tedd@sperling.com via PayPal.com. If you want to provide a link to my site, that would be good as well. However, there is no obligation to do either.
Enjoy,
tedd
www.heartofyourhome.ca
Of course I've tested this technique with IE 6 and it is not broken. This technique works for all modern browsers, and I am being very kind to IE6.
Have you validated your code for www.heartofyourhome.ca? If you had you would have found 14 errors and 3 warnings -- that's a lot!
Please understand that you can't take my code and wrap it in bad code and expect everything to work. You see, when you send bad code to a browser, you can't predict how that browser will react.
Always validate your code through the W3C (i.e., validator.w3.org).
tedd
This is by far the easiest, most flexible, and most robust round box solution I have found (and I have done quite a bit of searching). Just so you know, this is the code we are using on all 200+ CSN Stores (albeit with slightly different images). This was the first round box we tried, and after trying 3 other options we came back to your implementation. It worked right out of the box and as advertised.
Just wanted to say thanks.
-Jonathan
I've been looking for an efficient method of making expandable rounded corner boxes for quite a while. After about 20 previous tests, I can finally stop looking.
IMHO, your method is definitely the most flexible and browser friendly for now. I may re-visit the concept after CSS3 matures.
I've used your method (with minor mods) and have great results with W3C, both in CSS Level2 and XHTML 1.0 Strict.
My Mods:
1. I normally change the divs from class to id in order to get repeatable usage of the frames throughout the page.
2. I "@import" your box script from my main CSS so I can keep a modular design technique.
3. I use conditional statements in my HTML to make IE happy and still maintain W3C validation.
4. I sometimes use more than 1 "box style" in the same page by cloning the CSS as "box2, etc".
I've learned a lot of cool tricks from your articles and appreciate your intellectual generosity.
And, of course, have given you accreditation for your efforts in the sample I use.
M Wham
WhamWeb.com
I have been looking at the rounded corner box, I have created my own graphics but have found it near impossible to line up the different components? I guess I have have missed something out but not sure what it is. It is in the graphics stage that I am going wrong, am using photoshop but would it be easier in fireworks?
Regards
Gilly
The graphics can be tricky. It shouldn't make any difference what application you use.
I would suggest that you take the graphics I provided and look at them up-close and then try to change them to whatever colors you want while leaving the "edge" in the same place.
Once you see how the 8 graphics are used, then you'll have a better handle on how to roll-your-own.
Cheers,
tedd
Until CSS3, your simple-box for rounded/shadow div using 8-files is the best (most flexible) solution I have tried.
What is purpose of lines #2 through #6 in your CSS file above? It works fine without them. Thanks for sharing so many excellent examples.
Tom
I was wondering if there is any way to have the border not be white but transparant, when I change the image it does not work due to the repeating pattern.
Any ideas?
Thanks,
JB
Your example is great and simple thank you very much for this.
I have on little problem.
How can I change height? I know it changes hight automaticly with the content, but if I want the size to be the same all the time?
Thank you very much for simple and great round boxes.
I have one problem. I want to make height 100px but as I know the height is set automaticly depending on content. How can I make stable height?
First I want to thank you for this example. Its very easy to understand and to use.
I have one question though. How can I change the height of the box?
I know the box changes height automaticly with the content, but if I want the box to be same height all the time?
My apologies for not responding to your post. You see, my site receives literally hundreds of spam posing per day. I can't address all of the postings. In fact, I am going to remove the option from my site all together.
There are several ways to do what you want.
First, the outside box should remain as "id'=" in the HTML but the inside boxes should be changed to classes (i.e., class=) with a corresponding change in the css.
Second, the inside boxes must have to have different positions. You might consider doing absolute position of both via css OR float one of the boxes. The border classes should be named differently, such as class="r-lb" (right-box bottom left) and class="l_bl" (left-box bottom left).
Grnted this is a bit of programming and you'll have to play around with itto get it to work, but that's the way I would do it IF I was so inclined.
HTH's
tedd
Thanks for sharing this great work. I picked up a bug in IE8. When zooming at 75%, 125%, 175%, etc a 1px line appears next to the right border. When replacing your images with my own images, it looks a lot worse due to the contrast in colors. I have been struggling for 2 months trying to get rounded corners to work. This is my first website ever and I am under a lot of presuure to make this work. Please help.
Thanks,
Peter
I am new to CSS and just wondering: Why is background-position: 50% 100% for #bb? Why 50%?
Thanks in advance,
Peter
I am using in my site with just a few little modifications, like the top margin and the padding, to fit the content better. Thanks.
Great website you have. Plenty of tips and tricks :-)
I've looked at a couple of the comments above and if I may ............
1.Yes, it does work with Firefox;
2. If you want to change any of the colours just change the html - easy as that;
3. Like tedd, I created a separate css style sheet and stuffed everything in there;
4. Don't know what all the negative waves are about and you have exactly the right attitude - it's code for a box: if you want it to stand on its head or disembowel itself write the code yourself.
Keep up the good work!
Just having the same prob like Sasq.
I'm changing the gif to PNG with alpha transparency (i use my own roundcorner, just a very thin line, and i'm guessing the top, left, right and bottom border seemed to be overlapping with the round corner images, since it's having its transparency (alpha).
any way to handle this? though changing the corner to non transparency could fix the problem with overlapping, but still that boxed white non transparency when changing the background to some other color, e.g; blue.
anyway thanks for sharing!
I'm sorry, but there is just too much spam to review to provide answers. For example, for every honest question, there are over 1000 spams. I am leaving the comments here so that they may help others.
I find my time better spent providing more examples and attending to clients.
tedd