Tutorials

Welcome to the Absolute Web Dev tutorials page. All tutorials are made by request. If you need a tutorial, please email me with your request and I will create a tutorial that will fulfill your needs.

How to make an Expandable box using CSS.

Written by WebMaster   |  01/29/2009

This tutorial will cover the basics of how to make an expandable box in CSS. The advantages of using an expandable box are many. One is that when the browser window is restored down, the box will change its size to accommodate the browser window. Another is to make your website adjust to different monitor resolutions. These days, we are being bombarded with a large number of devices, and monitor innovations that web designers must adjust to. Many people are beginning to use handheld devices to view web pages and many LCD monitors are being sold that are widescreen and very high resolutions. Making a website elastic or fluid, so that it adjusts to a wide variety of user preferences, is becoming necessary. With that said, here we will learn how to build an expandable box, using plain CSS and HTML. You will need to download the following images in order to complete the tutorial. After you download the images, create a new HTML document and save it in the same location as the images.

Images:
bottom leftbottom righttop lefttop right

Create the Box container

First we need to create a simple box container that we will use to hold all of the box data. You need to place the usual "style" tags in the head section and place the following code in the "style" tags. We will make a class called "box." This class will have the sizing of the box and the background color. I used the "min-width" and "max-width" for my box sizing. You can use percentages or em's or whatever you want. I chose the background color orange #ff9900. In the body section of your HTML document, you will need to place the "div" tags with the class "box." We will be placing all of our following code into this "div" tag.

Head

.box {
   max-width: 500px;
   min-width: 300px;
   background-color: #ff9900;
}

Body

<div class="box">

</div>	

Create the content area.

Next we need to create the content area on the box.. I used an H2 heading tag and a P paragraph tag and placed them in a div tag that has the class name "boxcontent." Zero the margin on the h2 tag so that the top of the box will not have a huge gap between the header and the top of the box. I chose to justify the paragraph; but, you can do whatever you want. The "boxcontent" class separates the content from the "box" container. This is so you can apply padding to the content, without affecting the top and bottom "div" tags we will soon place in the "box" container. The code below shows what the "boxcontent" should look like. You will place the "boxcontent" div tags inside the "box" div tags.

Head

.box h2{
   margin: 0px;
}
.box p{
   text-align: justify;
}
.boxcontent {
   margin: 0px;
   padding: 0px 20px 0px 20px;
}

Body

<div class="boxcontent">
    <h2 align="center">Expandable Box</h2>
    <p>This box was made by using CSS and HTML.  
    The purpose was to make a box that would expand to the browser window. 
    Simply make your images, code, and boom, your done.</p>
</div>

Create the top rounded corners.

Now we will create the top rounded corners by making two classes, "topright" and "topleft." The property in the "topright" will be background. the url(tr.gif) is the link to the image for the top right and will display as the background of the div tag. The "no-repeat" is necessary to keep the background from repeating. The top value will display the image at the top of the div tag and the "right" property will place the image to the right of the div tag. You will do the same thing for the "topleft"; except, the top left will have the width and height set to the image size, which is 15px X 15px and in the background property the position needs to be set to "left." In the body section, you need to make two div tags, one inside the other one, with the class names "topright" and "topleft." These two div tags will be place in between the "box" div tag and the "boxcontent" div tag.

Head

.topright { 
   background: url(tr.gif) no-repeat top right; 
}
.topleft { 
   background: url(tl.gif) no-repeat top left; 
   width: 15px;
   height: 15px;
}

Body

  <div class="topright">
  <div class="topleft">
  </div>
  </div>
1 2 Next
Archive
TOP

  100% compatible with:
Firefox Explorer Opera Safari Flock Netscape Chrome

 100% valid CSS 3.0 and XHTML 1.0.
Valid CSS Valid XHTML