spacer

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

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

Web Project Manager
Aquent
US-PA-Collegeville

Justtechjobs.com Post A Job | Post A Resume
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

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]

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

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle

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

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