Difference between revisions of "CSS:Layouts102"

From mi-linux
Jump to navigationJump to search
Line 55: Line 55:
 
   float:left;
 
   float:left;
 
   border: 2px solid #0000ff;
 
   border: 2px solid #0000ff;
   margin: 10px;
+
   margin: 0px 0px 0px 10px;
 
   padding: 10px;
 
   padding: 10px;
}</nowiki>
+
  width: 200px;
 
+
}
The page should now look something more like this:
+
#right
 
+
{
[[Image:layoutscreen3.png]]
+
  float:right;
 
+
  border: 2px solid #0000ff;
Now we'll do the same for the content division
+
  margin: 0px 0px 10px 0px;
 +
  padding: 10px;
 +
  width: 200px;
 +
}
  
<nowiki>#content
+
#content
 
{
 
{
   border: 2px solid #ff0000;
+
   border: 2px solid #0000ff;
   margin: 10px;
+
   margin: 0px 240px 0px 250px;
 
   padding: 10px;
 
   padding: 10px;
 
}</nowiki>
 
}</nowiki>
  
The page should now look something more like this:
+
The new concepts introduced here are:
  
[[Image:layoutscreen4.png]]
+
*float:right
 +
*margins with 4 sets of numbers
  
This isn't what we want, but it emphasises the concept of "floating" - because the menu division is floating above the content division, the menu division passes BELOW the content division, and the content division is overlapping.
+
The page should now look something more like this:
 
 
There are a number of ways in CSS to fix this, but the easiest (in this example) is to also "float" the content division, since floating divisions appear side-by-side (as long as there is space) - change the content division CSS to also include a float statement:
 
 
 
<nowiki>#content
 
{
 
  float: left;
 
  border: 2px solid #ff0000;
 
  margin: 10px;
 
  padding: 10px;
 
}</nowiki>
 
 
 
The page should now look something more like this - this is pretty close to what we want:
 
  
[[Image:layoutscreen5.png]]
+
[[Image:layoutscreen23.png]]
  
 
=Ready to move on?=
 
=Ready to move on?=
 
When you're happy with the concepts introduced in this chapter, take a look at [[CSS:Layouts102]] for some more layout ideas, and how to implement them.
 
When you're happy with the concepts introduced in this chapter, take a look at [[CSS:Layouts102]] for some more layout ideas, and how to implement them.

Revision as of 15:11, 5 September 2007

Layout 2: 3 columns

The first stage to approach layouts is to draw a simple diagram of how you would like a web page to be presented:

A simple layout drawing

Stage 2: The Divisions

In order to achieve this layout we need three "divisions"

  • IMPORTANT
    • A "quirk" of CSS is that in order to achieve this kind of layout, we need to create the divisions in the following order:
      • menu, right, content

HTML Document - no CSS yet

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
  <HEAD>
     <TITLE>CSS 6</TITLE>
     <LINK rel="stylesheet" href="style6.css" type="text/css">
  </HEAD>
  <BODY>
    <DIV id="menu">
      This is the menu
      <UL>
        <LI>Item 1</LI>
        <LI>Item 2</LI>
        <LI>Item 3</LI>
        <LI>Item 4</LI>
        <LI>Item 5</LI>
      </UL>
    </DIV>
    <DIV id="right">
      Some interesting information in the right-hand column
    </DIV>
    <DIV id="content">
     <H1>This is the Content of the page</H1>
     <P>Very interesting content - wouldn't you agree?</P>
    </DIV>
  </BODY>
</HTML>

Stage 3: Match the divisions to the drawing

Create the following CSS file (and save as style6.css)

#menu {float:left}
#right {float:right}

Stage 4: Tidy up the presentation

Let's put some more content in the CSS to improve the appearance.

Modify the CSS to the following:

#menu
{
  float:left;
  border: 2px solid #0000ff;
  margin: 0px 0px 0px 10px;
  padding: 10px;
  width: 200px;
}  
#right
{
  float:right;
  border: 2px solid #0000ff;
  margin: 0px 0px 10px 0px;
  padding: 10px;
  width: 200px;
}

#content
{
  border: 2px solid #0000ff;
  margin: 0px 240px 0px 250px;
  padding: 10px;
}

The new concepts introduced here are:

  • float:right
  • margins with 4 sets of numbers

The page should now look something more like this:

Layoutscreen23.png

Ready to move on?

When you're happy with the concepts introduced in this chapter, take a look at CSS:Layouts102 for some more layout ideas, and how to implement them.