How to Format Web Pages Using CSS

Cascading Style Sheets, or CSS, describe the presentation and layout elements of Web pages. You may define any of hundreds of different rules in your CSS files, including font formatting, appearance, colors and element spacing. You may also create and use your own classes and ID selectors for extra programming freedom. You use CSS files by referencing them in your HTML pages. While you may find it a pain to modify your entire site when adding CSS to it, in the long run it will make modifying your entire site quick and simple.

Instructions

    • 1

      Open a blank text file and save it in the root directory for your website files. Use the ".css" extension, and give it a name, for example, "myStyleSheet.css."

    • 2

      Create type selectors by using existing HTML elements and specifying their formatting. For example:

      p {

      margin: 4px 0px;

      text-align: left;

      }

      Call this element in your HTML files by typing "<p>" and entering your text, and then closing the tag with "</p>."

    • 3

      Create class selectors with the dot operator (the "." symbol). For example:

      .content {

      height: 50px;

      font-size: 12px;

      }

      Call this class in your HTML files by typing "<p class="content">" and entering your text, and then closing the class by typing "</p>." Whenever you call the "content" class in your HTML files, anything within that element will have these formatting rules applied. If you have a "p" type selector as well as this class, the class rules override the type selector rules when used with a "p" element in your HTML.

    • 4

      Create ID selectors using the hash (the "#" symbol). For example:

      #navigationBar {

      width: 900px;

      height: 25px;

      margin: 15px 0px;

      padding: 0px;

      }

      Call this ID in your HTML files by typing "<div id="navigationBar">" and entering your text, and then closing it by typing "</div>." You should not use ID selectors more than once on your HTML pages. If you use them more than once for different sections of your page, you may create an ID conflict and see unexpected formatting that you will have to correct. In this example, you likely won't have more than one navigation bar per HTML file.

    • 5

      Save and close your CSS file, and then upload it to your server. Open each of your HTML pages and include the following line within the "<head>" section of each document:

      <link type="text/css" rel="stylesheet" href="path_to_file/myStyleSheet.css" media="screen" />

      Make sure you use the correct path to your CSS file in each document. Save your HTML documents, close them and upload them to your server.

Tips & Warnings

  • If you have several rules with the same declarations, you may use one line to define them all. For example, if you want the "h1" and "h2" tags to use the same font family, type "h1, h2 {font-family: font_name; }"

Related Searches:

References

Comments

You May Also Like

  • How to Use Div and Span in HTML and CSS

    Div and span elements often confuse people new to HTML and CSS, because they aren't semantically meaningful elements like headings, lists and...

  • How to Call Off a Wedding With Class

    "The Runaway Bride" isn't just a Julia Roberts movie. No amount of work invested in a wedding can protect it from the...

  • How to Use HTML & CSS Codes

    Knowledge of HTML (hypertext markup language) and CSS (cascading style sheets) codes is absolutely essential for building a Web page. After all,...

  • CSS Tutorial in PDF Format

    Cascading Style Sheets, or CSS, is used to define how a document will appear. This language is often used for web design,...

  • How to Use CSS for Image Rollover

    Open up your HTML file in an editor or create a new one. Place <div> and </div> tags somewhere between the <body>...

  • 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 Know Blogger CSS Rules

    Want to customize your Blogger blog? Use this simple trick to match the CSS rules in a Blogger template to the appearance...

  • How to Create a 5 Column Tableless CSS Website

    Creating a workable layout for your website without using tables is usually done with cascading style sheets (or CSS), the "div" element...

  • Kansas ATV Laws

    Kansas ATV Laws. ATVs are considered motor vehicles in Kansas so they are regulated by, and registered with, the Kansas Department of...

  • JavaScript Tutorial and Reference

    JavaScript is a light programming language with many words and signs, tags, and operators (Remember your elementary math class? An equals sign...

Related Ads

Featured