Lori's Web Design
my facebook     my twitter     My blog

How to Add Borders Around a Web Page with CSS


This CSS tip will explain how to add a border around the edge of the main container on your webpage, or a box or table or any other item on your website.

Add a Border Around a Webpage

Let's assume you want a webpage that is 900 pixels wide, centered in the browser, with a white background and light gray border or frame. We will call this CSS class a "Container" and apply the css to that class. If you want a different colored background for the rest of the page that needs to go in your body tag in the CSS file.

Here is the code for the CSS file:
The Margin-left and Margin-right will center the div on the page or parent container.
.container {width:900px;
      margin-left:auto;
      margin-right:auto;
      border:1px solid #cccccc;
      background:#ffffff; }

Here is the code for the webpage:

<div class="container">
Your Website Content Goes Here
</div>


The result should look like this:

Your
Website Content
Goes Here

Frame a Web Page

page with a triple border You can also add multiple borders so the page looks like it's within a frame as in the image on the right. You need a container and then 2 borders with varying padding or margin widths. Notice the outer border allows the page to be centered within the broswer screen. Play with the widths or colors to make it fit your color scheme. You can see the page frame on Millcreek Construction.

Here is the css:

#container {width:825px;
      border:1px solid #996666;
      margin:0;
      padding:0;
.border1 {width:827px;
      border:3px solid #996633;
      margin:1px;
      padding:2px;}
.border2 {width:839px;
      border:1px solid #996666;
      margin:12px auto 12px auto;}

Here is the HTML:

<div class="border2">
<div class="border1">
<div id="container">

Content goes here

</div> <!-- End Container -->
</div> <!-- End Border1 -->
</div> <!-- End Border2 -->


Add a Border Around a Box

You can do the same thing with a box. This box is 200 pixels wide, with a white background and a blue border.

Here is the code for the CSS file:

.box200 {width:200px;
      margin-left:auto;
      margin-right:auto;
      border:1px solid #3399ff;
      background:#ffffff; }

Here is the code for your webpage:

<div class="box200">
Your Website Content Goes Here
</div>

The result should look like this:

Your
Website Content
Goes Here

Add a Border Around a Table

If you'd like to add a border around the outside of a table (instead of every table cell) just set up a class for border and apply it to your main table cell:

Here is the code for the CSS file:

.border {border:1px solid #cccccc;}


Here is the code for your webpage:

<table align="center" width="600" cellpadding="0" border="0" class="border">
<tr><td>
Your Website Content Goes Here
</td></tr></table>

The result should look like this.

Your WebsiteContentGoes Here


order SEO analysis

Lori's Web Design
Copyright © August 28, 2009 - updated 2011-11-12
All Rights Reserved

Return to CSS TIPS or see frequently updated Seo Tips on my home page




 
Serving Spokane, WA, Colfax WA, Deer Park WA, Medical Lake WA, all of Eastern WA and across the USA

Lori's Web Design Spokane: 509-443-8693
or Colfax: 509-397-6000

Copyright © 2000 - 2012
All Rights Reserved