spacer

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

home / programming / css_borders / 1 current pageTo page 2To page 3
[next]

ASP 3.0/.NET Developer
Jupitermedia
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
SaaS Tool Offers Custom Database Development
Microsoft’s Automated Agent: Can We Talk?
Borland Finally Sells CodeGear

How to Add Fluid Borders to Your Boxes with CSS

By Stu Nicholls.

Introduction

In my last tutorial you learned how to style a definition list. This week, I will take this process a little further and show you how to add different fluid borders to your boxes using just CSS.

As with previous tutorials I will take you through these styles in easy to understand steps with diagrams when necessary.

The following link will show you five sample Krazy Korners and I'll show you how to style this type of border. If you resize your browser window you will see that these borders are fluid and stay in shape. Resize the text and they will also stay in shape. The only small problem is found in Internet Explorer which will continue to shrink the top and bottom borders after the main content div has stopped shrinking. This, however, can be overcome using my min-width hack for Internet Explorer .

Krazy Korner Examples

In my experience, this method works with nearly all browsers and operating systems.

Method

Basic idea

The basic idea behind Krazy Korners is that we style the corners using four or five pixel high strips before and after the main content div. These strips are created using styled <b></b> tags. <b> tags have been used because they are faster to type than <span></span> and take up less file space (as good a reason as any).

Each strip is created using a background color, a left and right border color and a left and right margin. The basic curved corner was described in detail in my previous article but to recap I will reproduce the enlarged diagram again to show how each strip was organized.

snazzy diagram

The basic curved corner is comprised of four strips labelled b1 to b4 and in the example above the background color is a pale gold, the border color is white and the outer background color is light grey. Krazy Korners work best with pastel colors as these tend to give a slightly antialiased look (white works really well and is used for most of these examples). Bright colors create a more jagged appearance.

Example 1

This example has reverse curves to give the effect of cut-out curved corners and the enlarged view below shows how this is achieved.

example 1 diagram

The XHTML is below:

<div class="curved">
<b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>
<div class="boxcontent">
<h1>Example 1</h1>
<p>A box with cutout corners</p>
</div>
<b class="b4"></b><b class="b3"></b><b class="b2"></b><b class="b1"></b>
</div>

and the styling will be:

/* Curved cutout Borders*/

.curved {
  background: transparent; 
  width:40%;
  }
.curved h1, .curved p {
  margin:0 10px;
  }
.curved h1 {
  font-size:2em; 
  color:#fff;
  }
.curved p {
  padding-bottom:0.5em;
  }
.curved .b1 {
  display:block; 
  overflow:hidden; 
  height:1px; 
  margin:0 4px; 
  background:#fff;
  font-size:1px;
  }
.curved .b2 {
  display:block; 
  overflow:hidden; 
  height:1px; 
  margin:0 4px; 
  background:#e0cea3; 
  border-left:1px solid #fff; 
  border-right:1px solid #fff; 
  margin:0 4px; 
  height:2px;
  font-size:1px;
  }
.curved .b3 {
  display:block; 
  overflow:hidden; 
  height:1px; 
  margin:0 4px; 
  background:#e0cea3; 
  border-left:1px solid #fff; 
  border-right:1px solid #fff; 
  margin:0 3px;
  font-size:1px;
  }
.curved .b4 {
  display:block; 
  overflow:hidden; 
  height:1px; 
  margin:0 4px; 
  background:#e0cea3; 
  border-left:1px solid #fff; 
  border-right:1px solid #fff; 
  margin:0; height:1px; 
  border-width:0 3px 0 3px;
  font-size:1px;
  }
.curved .boxcontent {
  display:block; 
  background:#e0cea3; 
  border:0 solid #fff; 
  border-width:0 1px;
  }

It's IMPORTANT to specify a font-size of 1px for each of the lines of the curve. Without this IE5.5 will put a gap between each line.

The outer div class 'curved' holds the whole shape together and the width can be set in pixels, ems or percent.

Since the classes .b1, .b2, .b3 and .b4 share common styling the above css could be condensed into the following style.

/* Curved cutout Borders*/
.curved {
  background:transparent; 
  width:40%;
  }
.curved h1, .curved p {
  margin:0 10px;
  }
.curved h1 {
  font-size:2em; 
  color:#fff;
  }
.curved p {
  padding-bottom:0.5em;
  }
.curved .b1, .curved .b2, .curved .b3, .curved .b4 {
  display:block; 
  overflow:hidden; 
  height:1px;
  font-size:1px;
  }
.curved .b2, .curved .b3, .curved .b4 {
  background:#e0cea3; 
  border-left:1px solid #fff; 
  border-right:1px solid #fff;
  }
.curved .b1 {
  margin:0 4px; 
  background:#fff;
  }
.curved .b2 {
  margin:0 4px; 
  height:2px;
  }
.curved .b3 {
  margin:0 3px;
  }
.curved .b4 {
  margin:0; 
  height:1px; 
  border-width:0 3px 0 3px;
  }
.curved .boxcontent {
  display:block; 
  background:#e0cea3; 
  border:0 solid #fff; 
  border-width:0 1px;
  }

Example 2

This example has a narrowing curve to create the effect of serif corners and the enlarged view below shows how this is achieved.

example 2 diagram

home / programming / css_borders / 1 current pageTo page 2To page 3
[next]



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
How to Create an Ajax Autocomplete Text Field: Part 6 · Software Engineering for Ajax · Perl Pragma Primer
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Using File Virtualization for Disaster Recovery · VoIP Security: SIP—Versatile but Vulnerable · Around the World in 80 Nodes

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

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