spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / css_borders / 1 To page 1To page 2current page
[previous]

Software Developer / Programmer - Interview NOW!
Next Step Systems
US-IL-Des Plaines

Justtechjobs.com Post A Job | Post A Resume
Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies


How to Add Fluid Borders to Your Boxes with CSS

Example 5

This is similar to example 4 but this time the shading is reversed to give an inset appearance to the border.

example 5 diagram
  • b1 - 1px high line with a grey 5 background and a left/right margin of 5px
  • b2 - 1px high line with grey 3 background, a left border 2px solid grey 5, a right border 2px solid grey 4 and a left/right margin of 3px
  • b3 - 1px high line with a grey 3 background, a left border 1px solid grey 5, a right border 1px solid grey 2 and a left/right margin of 2px
  • b4 - 2px high line with a grey 3 background, a left border 1px solid grey 5, a right border 1px solid grey 1 and a left/right margin of 1px
  • boxcontent - a grey 3 background, a left border 1px solid grey 5, a right border 1px solid white and no margin
  • b4b - 2px high line with a grey 3 background, a left border 1px solid grey 4, a right border 1px solid white and a left/right margin of 1px
  • b3b - 1px high line with a grey 3 background, a left border 1px solid grey 2, a right border 1px solid white and a left/right margin of 2px
  • b2b - 1px high line with grey 3 background, a left border 2px solid grey 1, a right border 2px solid white and a left/right margin of 3px
  • b1b - 1px high line with a white background and a left/right margin of 5px
The XHTML is below:

<div class="inset">
<b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>
<div class="boxcontent">
<h1>Example 5</h1>
<p>Rounded corners with inset borders</p>
</div>
<b class="b4b"></b><b class="b3b"></b><b class="b2b"></b><b class="b1b"></b>
</div>

and the styling, after condensing, will be:

/* Inset 3D Curved */
.inset {
  background:transparent;
  width:40%;
  }
.inset h1, .inset p {
  margin:0 10px;
  }
.inset h1 {
  font-size:2em; color:#fff;
  }
.inset p {
  padding-bottom:0.5em;
  }
.inset .b1, .inset .b2, .inset .b3, .inset .b4, .inset .b1b, .inset .b2b, .inset .b3b, .inset .b4b {
  display:block; 
  overflow:hidden;
  font-size:1px;
  }
.inset .b1, .inset .b2, .inset .b3, .inset .b1b, .inset .b2b, .inset .b3b {
  height:1px;
  }
.inset .b2 {
  background:#ccc; 
  border-left:1px solid #999; 
  border-right:1px solid #aaa;
  }
.inset .b3 {
  background:#ccc; 
  border-left:1px solid #999; 
  border-right:1px solid #ddd;
  }
.inset .b4 {
  background:#ccc; 
  border-left:1px solid #999; 
  border-right:1px solid #eee;
  }
.inset .b4b {
  background:#ccc; 
  border-left:1px solid #aaa; 
  border-right:1px solid #fff;
  }
.inset .b3b {
  background:#ccc; 
  border-left:1px solid #ddd; 
  border-right:1px solid #fff;
  }
.inset .b2b {
  background:#ccc; 
  border-left:1px solid #eee; 
  border-right:1px solid #fff;
  }
.inset .b1 {
  margin:0 5px; 
  background:#999;
  }
.inset .b2, .inset .b2b {
  margin:0 3px; 
  border-width:0 2px;
  }
.inset .b3, .inset .b3b {
  margin:0 2px;
  }
.inset .b4, .inset .b4b {
  height:2px; margin:0 1px;
  }
.inset .b1b {
  margin:0 5px; 
  background:#fff;
  }
.inset .boxcontent {
  display:block; 
  background:#ccc; 
  border-left:1px solid #999; 
  border-right:1px solid #fff;
  }

Conclusion

You may have noticed that all the above style sheets have the same initial setup for <p> and <h1> tags as shown below:

.inset h1, .inset p {
  margin:0 10px;
  }
.inset h1 {
  font-size:2em; color:#fff;
  }
.inset p {
  padding-bottom:0.5em;
  }

Using this method of producing Krazy Korners, it's necessary to get rid of any margins at the top and bottom of the boxcontents div as these will cause a gap to appear between the boxcontent and the curved corners. The simplest way to do this with my examples is to get rid of the top and bottom margins altogether and apply a little bottom padding to the <p> tag to raise it away from the bottom. You can, of course style this as you wish for your application. As you can see, the styles for Krazy Korners are endless and just require a little imagination.

About the Author

Stu's website documents his attempts at understanding and exploring the possibilities of CSS. From standard navigation links to his more bizarre experimental techniques. All of his examples are produced with JUST CSS--no javascript, or any other language, has been used in any of the examples. [Editor's note: Prepare to be amazed!] http://www.stunicholls.myby.co.uk/


home / programming / css_borders / 1 To page 1To page 2current page
[previous]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji

Created: March 27, 2003
Revised: May 25, 2005

URL: http://webreference.com/programming/css_borders/1