Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > CSS

Building a Page with CSS-P

📄 Contents

  1. Steps to Page-Building
  2. About the Article
Designing a page with CSS-P can at first present a bit of a challenge. Learn how to build an effective, liquid page design starting with a simple sample project.
Like this article? We recommend

Like this article? We recommend

Introduction

Figure 1 shows a diagram of the sort of simple page we are going to build. It has a top banner and two columns—a Menu column and a Content column.

Figure 1Figure 1 The Plan: a really simple starting project.

This is the sort of page we all built when we were trying to learn HTML in the first place. A good, basic design like this will help you get to grips with the techniques.

TIP

You can find all the code examples for this exercise at http://www.dreamweaverfever.com.

Steps to Page-Building

Step 1: The Page

It may be tempting to jump right in and start doing things with CSS, but the first thing you need to set up is a basic page. Our page is going to contain three main blocks: a top banner, a menu for navigation, and our main content. We'll create each of these in a division so that they can be easily addressed as separate block elements.

Top Banner

The first item to place in the page is the top banner. We'll place this in its own division with an ID of banner.

<div id="banner">
  <h1>Fluid Positions Inc</h1>
</div>

Things don't get much simpler than that. The name of the imaginary online recruitment company for this site has been placed inside <h1> tags because it's the highest level of heading on the page.

Navigation Menu

Next up is the division into which we will place a series of navigational links. The important thing to note is that I haven't separated the links with line breaks, even though I want each link to live on its own line. I'll put the breaks in later in the CSS. The important thing here is to keep the structure, so I have to consider how the page will display with no style sheet attached. This also makes the page more flexible if I decide to change the layout in the future.

We'll call this one menu. Here's how the menu division looks:

<div id="menu">
  <p>
    <a href="/index.html">Home</a>
    <a href="/about/">About us</a>
    <a href="/positions/">Find a Job</a>
    <a href="/contact/">Contact us</a>
  </p>
</div>

I've wrapped the whole lot in a paragraph tag to give it the structure of a paragraph.

Content Area

The third and final block is the main content area. The heading within this area is a level-two heading; it's the next most important thing after the company name. I also have included a couple of paragraphs of text to pad out the design and make it easy to work with. We'll call this division just content:

<div id="content">
  <h2>We can find you a better job!</h2>
  <p> The following text consists of a mock Latin which has been
  based upon the average frequency of characters and word lengths
  of the English language in order to reproduce a
  <a href="javascript:;">reasonably accurate</a> overall visual
  impression. Lorem ipsum dolor sit amet, consectetur adipscing elit,
  sed diam nonnumy eiusmod tempor incidunt ut labore et dolore magna
  aliquam erat volupat. </p>
  <p> Et harumd dereud facilis est er expedit distinct. Nam liber
  a tempor cum soluta nobis eligend optio comque nihil quod a impedit
  anim id quod maxim placeat facer <a href="javascript:;">possim
  omnis</a> es voluptas assumenda est, omnis dolor repellend. Temporem
  autem quinsud et aur office debit aut tum rerum necesit atib saepe
  veniet ut er repudiand sint et molestia non este recusand.
  </p>
</div>

Attaching a Style Sheet

The only thing left to do before we're ready to write some CSS is to create and attach a new blank style sheet to the page. You can create your style sheets in a lot of different ways. Dreamweaver has its own editor—although it is something of a token gesture. Many developers code their CSS by hand, often in a dedicated CSS editor such as Bradbury Software's TopStyle. Nick Bradbury, creator of TopStyle, was the developer behind HomeSite before (and while) it was bought by Allaire and then later Macromedia. TopStyle is generally considered the best CSS editor for the Windows platform and it integrates with Dreamweaver extremely well.

For Macintosh users, Westciv Webware have a number of extremely capable CSS tools, as well as a wealth of useful CSS information on their web site.

To get the style sheet going, you can start by defining a few quick rules. The first makes sure the <body> tag doesn't have any default margins or padding set. The following two are just a bit of text formatting for the two levels of heading used.

body{
  margin : 0px;
  padding : 0px;
}

h1{
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 36px;
  white-space : nowrap;
  padding : 10px 0px 0px 10px;
  margin : 0px;
}

h2{
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 24px;
  font-weight : normal;
}

Step 2: Positioning the Banner

The first thing to do in this nice clean style sheet is to position the top banner. As you have seen, the banner is just a division with a top-level heading inside of it. I want the banner to stretch right across the window, and be about 70 pixels high. I am going to give it a gray background and back that up with white as my foreground color to ensure anything within it can be clearly read.

Because this is a named element being positioned, the CSS selector should start with a hash, or pound, (#) sign.

#banner{
  top : 0px;
  left : 0px;
  width : 100%;
  height : 70px;
  color : white;
  background-color : gray;
  z-index : 100;
}

As you can see, I have also given the banner a Z-index (stacking order) of 100 to make sure it is always on the top of the pile. Previewing your page at this point might come as a bit of a surprise, because all sorts of items will have started overlapping. Don't worry; it's going to look a bit strange until all the elements are properly positioned.

Step 3: Positioning the Menu

Up next is the menu. This is going to sit on the left side of the window, just under the banner. It will be 150 pixels wide.

#menu{
  position : absolute;
  top : 70px;
  left : 0px;
  width : 150px;
  color : black;
  background-color : transparent;
  padding-left : 30px;
  padding-top : 74px;
  z-index: 10;
}

Note that I have used absolute positioning to place the menu. That is because it shouldn't be reliant on any other elements in the page. I always want it to start 70 pixels from the top, and tight against the left edge. The padding is to move the content of the menu away from the top and the left.

Previewing the page again at this point, note that everything still looks a mess. Most notable, however, is that the navigational links are not wrapping onto their own lines. Also the links could really do with a little formatting to make them look smarter. To do this, we need to redefine the <a> tag. However, we want this rule to affect links only within the menu and not the rest of the page. The easiest way to accomplish this is to create a selector that says "any link within the item with an ID of menu." This is how we do it:

#menu a{
  font-family: verdana, Geneva, Arial, Helvetica, sans-serif;
  font-size : 11px;
  color : maroon;
  background-color : transparent;
  text-decoration : none;
  display : block;
}

The last two properties set are the most interesting. Text-decoration refers to the browser's method for visually indicating a link—obviously an underline by default. There are other options—overline is one—but I have opted to have no text-decoration because it should be obvious that these are links.

The final property is pure magic. Display : block; tells the browser to treat the element as if it were a block element. As you are aware, block-level elements (such as tables and forms) always break onto a new line when displayed, so the effect this has is to push each link onto its own line, giving the arrangement we were after.

All that's left to do on the menu is to make the links react on hover, and to add a little line spacing.

#menu a:hover{
  color : navy;
  background-color : transparent;
  text-decoration : underline;
}
#menu p{
  line-height : 140%;
}

Step 4: Positioning the Content Area

The last item to deal with is the content area. It is essential that we manage to keep the content area flexible so that the text gently reflows with the browser window. I usually find it best not to position the main content division itself, but instead mold its dimensions using margins and otherwise let it sit in its natural position in the page. This approach tends to avoid strange problems with setting the width of an object to a certain dimension and running the risk of forcing unnecessary scrollbars.

I also have added a left border to the content area, to provide a small dividing line between the menu and the content.

#content{
  margin-top : 0px;
  margin-left : 180px;
  margin-right : 30px;
  padding-top : 10px;
  padding-left : 20px;
  border-left : dashed 1px silver;
  z-index: 50;
}

Most of the padding and margin settings are just to place the content away from the edges. The important one to note is the left margin. This is set to 180 pixels to allow space for the menu (which is 150 pixels) to sit. The menu is actually set inside the margin of the main content, and both items have their left extreme on the far left of the browser window. This approach proves very useful to circumvent the otherwise tricky 100% minus 150-pixel problems with making the content area flexible.

All that's left to do is add some formatting to the text itself, and to give the links within the content some styling of their own.

#content p{
  line-height : 140%;
  font-family : verdana, Geneva, Arial, Helvetica, sans-serif;
  font-size : 12px;
}

#content a{
  text-decoration : underline;
  color : maroon;
  background-color : transparent;
}

#content a:hover{
  color : maroon;
  background-color: #eee;
  text-decoration : underline overline;
}

A quick preview in your browser should now reveal a basic but tidy page with a flexible layout.

Step 5: Browser Testing

A crucial part of working with CSS-P—just like any other aspect of web development—is to check your work in as many browsers as possible.

To be sure that your page will work correctly for all those viewing our site, you must open the page in different browsers and perform a number of tests. In the case of the page we have been working on, I think that these are reasonable tests:

  1. Is the content displayed?

  2. Do the columns take up the correct width without overlapping?

  3. When resizing the window, does the page adjust correctly?

  4. Do scrollbars appear in the correct places?

  5. Do any scrollbars work as expected?

  6. Are any other abnormalities apparent?

With the page in question, these six simple tests should reveal most abnormalities. After all, this is quite a simple page and we shouldn't really encounter too many problems.

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020