We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25322
    • 78 Posts
    Hi
    Someone has asked me for some help on building their small site  in xhtml/css. There are 4 or 5 divs on each page. Each div has a background color of say red and has rounded corners. Each one of these divs has a 10 pixel white border which also has rounded corners.
    As I will have so many round corner divs on each page what is the quickest way to go about doing this which will be w3c compliant?
    I had a look at ryans technique with one image but I am not sure if that will work for this.

    Thanks
      • 24414
      • 45 Posts
      If you know the width of your boxes then the best way may be to just give them image backgrounds, made of the rounded-corner box image split in two (kind of like the sliding doors/A List Apart technique turned sideways).

      Make one box far bigger than it needs to be and use the small one as an actual image element. I often also use this this for clearing floats too.

      The large image will be your background which will resize as your user resizes text. Use background-position if you have to use the HTML image element in the top of your box.

      .rounded-corners-box {
      	width: 500px;
      	background: url(/path/to/our/rounded-corners-image-large.img) no-repeat;
      	}
      
      .corners-bottom {
      	display: block;
      	}
      
      <div class="rounded-corners-box">
      	<h2>This is some content</h2>
      	<p>Some content</p>
      	<p>Some content</p>
      	<p>Some content</p>
      	<p>Some content</p>
      	<img class="corners-bottom" src="/path/to/our/rounded-corner-image-small.img" alt="">
      </div>
      


      You can see examples of this in the sidebar on the home page at my site (URL in my sig).

      If you want to save the messy extra fluff image you can insert it with JavaScript to keep your HTML clean.