How to Create CSS Classes for Web Page Layouts

Classes of Cascading Style Sheets (CSS) allow web designers to assign similar attributes to multiple HTML tags without having to create entries for each one. Rather than placing styles, such as color, font size, height and width directly in the HTML tags, all style attributes are placed in a separate file called a CSS file. The HTML file is linked to the CSS, and when a website visitor accesses the HTML file in a web browser, the HTML loads the attributes in the CSS file and applies them to the appropriate HTML tags.

Things You'll Need

  • Text editor
  • Web browser
Show More

Instructions

  1. Setup the CSS file

    • 1

      Create a regular HTML file. It must at least contain the following tags:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <title>Website Name</title>
      </head>
      <body>
      </body>
      </html>

    • 2

      Create a directory within the HTML documents directory and call it "styles".

    • 3

      Make a new file in the "styles" directory called "style.css". It should be an empty text file.

    • 4

      Edit the HTML file and add the following line directly above the </head> tag:

      <link rel="stylesheet" type="text/css" href="styles/style.css" />

    Assign Classes

    • 5

      Edit the HTML file.

    • 6

      Create a generic box that you will use to apply styles For example:

      <div class="classname"></div>

    • 7

      Replace "classname" with a name that best describes your class.

    • 8

      Assign the same class name to any tag you want to have the same features. For example, if you have 10 boxes and five of them will have the exact same look, assign the class to those five tags.

    • 9

      For each group elements that has a unique style, assign a new class for it.

    Specify styles for classes

    • 10

      Edit the CSS file.

    • 11

      Create an entry for each class that you have assigned using the following format:

      .classname { }

    • 12

      Assign attributes to the classes. For example:

      .classname {height: 30px; background-color: #ffffff}

    • 13

      Repeat the same steps for each class, and be sure to save your documents periodically.

    • 14

      Open the HTML file in a web browser at any time to check your work, and also check the code with a CSS validator.

Tips & Warnings

  • The are hundreds of CSS styles that you can assign. Use the link listed in Resources to learn more about them. Remember to save your documents and check your work frequently.

Related Searches:

References

Resources

Comments

You May Also Like

  • How to Create Scroll Boxes

    A scroll box is a wonderful little piece of coding that can save space and add convenient functionality to a website. A...

  • How to Create a CSS Calendar

    Calendars are often used for selecting dates for appointments, airline flights, hotel availability and when to send e-cards. Usually you see calendars...

  • How to Define a CSS Class Style

    CSS styles define styles for different sections of your web pages, including links, tables, and div sections. You can define a CSS...

  • How to Do a Bibliography

    Comments. You May Also Like. How to Do a Bibliography Sheet. By doing a bibliography sheet, you provide evidence on the validity...

  • How to Create Web Page Templates Using CSS

    Creating the basic files for a web page that you can use over and over again keeps web design simple and efficient....

  • How to Format a Form With CSS

    Before Cascading Style Sheets existed, Web developers placed visual styling definitions inside their HTML tags. These definitions, such as font color and...

  • How to Use CSS Classes and IDs

    Proper use of CSS IDs and classes can save you time in maintaining your style sheets, save your users time when they...

  • How to Create One CSS File for Your Entire Website

    You May Also Like. How to Create a CSS File in XML. XML is a computer language that is simplistic in nature....

  • How to Design Web Pages With CSS

    Since the first web browsers became available, web page designers have struggled to make the way pages look and act on the...

  • How to Protect Web Page Images in CSS

    You cannot prevent Internet users from copying your HTML and Web images. Internet surfers can simply click "View Source" and see your...

  • How to Create a CSS File in a Web Application

    For many years, HTML was the primary language used to construct and format Web pages. Today, HTML is still required for the...

  • How to Create a CSS Header

    Cascading style sheets, or CSS, help you organize the design of your Web pages through the use of classes. A class is...

  • How to Create a CSS Web Page

    Most websites today use a combination of CSS (Cascading Style Sheets) and HTML (Hypertext Markup Language) or XHTML (Extensible Hypertext Markup Language)....

  • HTML Table Align Tutorial

    A HyperText Markup Language (HTML) table allows you to display your tabular data on a web page in an organized fashion. In...

  • How to Override CSS Inside DIV Classes

    Cascading Style Sheets use properties inherited from parent elements to determine how objects within an element are styled, unless CSS is used...

  • How to Create CSS HTML From Photoshop

    Photoshop is a graphic design and photo editing application developed by Adobe. It is the market leader in digital image editing software....

  • CSS Tutorial

    Cascading Style Sheets (CSS) is a method used to control the layout of web pages. The styles control the font, background color...

  • How To Make Tables in CSS

    Creating tables using Cascading Style Sheets (CSS) is an advanced way of displaying data or to create a page layout. CSS allows...

  • How to Create a 5 Column Tableless CSS Website Template

    Laying out a web page with cascading style sheets instead of tables can be difficult for people who are used to table-based...

Related Ads

Featured