CSS Flexible rounded corners box with one (single) background image

Monday, 23 June 2008

Here's my technique for rendering rounded corner boxes for Joomla. It's flexible, it can stretch both horizontally and vertically.

I use one large background image cleverly positioned in each of module's nested divs.

One image means one HTTP request, and this is as good as it gets for loading speed. The only limitation with this technnique is that a module cannot be infinitely large, it must be a bit smaller than the background image. The image i'm using is 775px wide x 1969px tall, so it should accomodate very large modules. It only weights 15.6KB

There are no IE hacks, it just works in all browsers(tested in Firefox, Opera 9, IE6, IE7).

So, let's get on to the CSS:

 

/*TeachMeJoomla's
flexible rounded corners module CSS*/
 /*image setup */
 div.module-green, div.module-green div{
 background:
url('images/rounded_green.jpg');
 
 }
 /*replaced with TeachMeJoomla's single image technique*/
 
div.module-green
 {
 padding: 0px 0px 0px 0px;
 margin:0px 0px 0px 0px;
 background-repeat:no-repeat;
 background-position:bottom left;
 height:1%;
 width:auto;
 }
 
div.module-green div
 
 {
 margin:0px 0px 0px 13px;
 background-repeat:no-repeat;
 background-position: bottom right;
 
 padding: 0px 0px 13px 0px;
 width:auto;
 }
 div.module-green div div 
 {
 
background-position: top right;
 
margin: 0px 0px 0px 0px; 
 
padding: 0px 0px 0px 0px;
 }
 div.module-green div div div 
 {
 
margin:0px 13px 0px -13px;
 
background-position: top left;
 
padding: 13px 0px 0px 13px;
 }
 /*reset nested divs*/
 
div.module-green div div div div
 {
 padding:0px 0px 0px 0px;
 margin:0px 0px 0px 0px;
 
background:none;
 
background-image: none;
 
background-position: top left;
 
background-repeat: repeat;
 
background-color: transparent;
 
width:100%;
 }

 

Here's the HTML, generated from your template  by

 

  mosLoadPosition('module_position',-3)

 

or (Joomla! 1.5)

 

<jdoc:include type="modules" name="module_position" 
 style="rounded"   headerLevel="3" />

 


 

<div class="module-green">
 
<div>
 
<div>
 
<div>
 
<p>
 
Look! I'm a flexible rounded corners box 
 with 1 single background image!
 
here's more HTML
 
</p>
 
<ul>
 
<li>item</li>
 
<li>item</li>
 
<li>item</li>
 
<li>item</li>
 
</ul>
 
 
</div>
 
</div>
 
</div>
 </div>

 

 

And here's the final rendered box. 

Look! I'm a flexible rounded corners box with 1 single background image!

Here's more HTML

  • item
  • item
  • item
  • item 

Are you a Joomla/PHP/Web developer? You may want to check our freelance marketplaces list.



Give us some social love (it really works now)!

Reddit! Del.icio.us! StumbleUpon! Yahoo! Swik!



Comments (5)
RSS comments
1. Semi Trans PNG12-03-2009 15:19

Hi, Firstly, thank you SO much for this tutorial. I have been looking around the web for some time to try and get rounded corners working :sigh and I can say right away that this was the simplest and most effective I have found so far. 
 
I have implemented the code successfully for FF and Chrome, but not getting it happening with IE7 yet .. I have tried a strict doctype but its not happening.... but am still looking as I have other IE issues so its more than likley my problem :)  
 
Anyway... Would you have any ideas on changes to this, or technique to do this with a semi tran png. Obviously with a direct implementation, there are overlaps with the transparency. 
 
I am looking to use a fairly fancy graphic, so don't think mochaui will work for me. 
 
I have tried the Joomla 4x image tutorial, and read about 100 forums with 'corrections' to it, but just cant seem to make it happen (someone needs to detail/document) the margin and padding! :). Besides that, I think the single image technique is a much better idea. 
 
I have used the "even more rounded corners" single image technique to do my headers and footers (entire blocks) with a semi trans image and it is working well, but not sure if it could be applied to module styling. 
 
Anyway, just thought I would ask. 
 
Feel free to contact direct if this is not something you want to do 'publicly' 
 
Either way, thanks for the template. 
 
Cheers

2. @dave: DOCTYPE29-08-2008 11:47
Tudor

Try using a strict DOCTYPE 
browser reset CSS should also be included before the rounded corner CSS. 
If it still does not work, there may be issues with your CSS layout

3. does not work in ie7 for me13-07-2008 02:05

I tried this out and it worked great for firefox, but, no go for ie7. Kan't seem to figure out why...

4. Canvas corners28-06-2008 16:04

You could actually have the browser draw them by using canvas and it's IE "port". 
Mocha UI implements this 
http://mochaui.com/demo/

5. What about transparent corners28-06-2008 05:19

Am using CSS very similar to yours, but my problem is that my client's site has watermark background, and I need transparent corners. I've done the graphic, that's not the problem, it's just that the top level div background is seen under the bottom corners. Without trying your solution, which is nice and clean, it doesn't look to quite do it. I can horizontally margin the top two divs, that's fine. But the bottom corners remain a mystery. Any ideas welcome!

Write Comment
  • Please keep the topic of messages relevant to the subject of the article.
  • Please don't use comments to plug your web site. Links are rel='nofollow'-ed
  • Please refresh the page if you're having trouble with the security image code
Name:
E-mail
Homepage
Title:
Comment:

:) :grin ;) 8) :p
:roll :eek :upset :zzz :sigh
:? :cry :( :x
Code:* Code

Last Updated ( Thursday, 18 June 2009 )
 

Europe freelancer directory

Newsletter

Subscribe to TeachMeJoomla's newsletter
Name:
Email:


Auto tags

joomla rounded corners

flexible round corner

css background image corner

rounded corners joomla

css background image rounded corners

0px 0px repeat transparent css

background image rounded

rounded corner background image

css rounded background image

joomla template rounded corners

css module box

joomla 1.7 rounded buttons

css rounded corners with background image

background image joomla module

rounded borders joomla css

newsletter box css

flexible background

joomla rounded menu

images rounded corners joomla

rounded corner green

newsletter rounded corners

flexible background css