Web Design Stuff
HTML Tutorials    CSS Tutorials    Web Hosting   Resources
Create a Web Page 101
Making Web Pages Intro What is a Web Page? Why Make a Web Page? The History of HTML Learn HTML or XHTML?
Basic HTML
Basic HTML Tutorials Basic HTML Necessities How to Make a Web Page How to Edit a Web Page The Basics of HTML Tags Basic HTML Page Structure HTML Attributes
HTML Font Codes
HTML Font Codes Intro HTML Font Color Codes HTML Font Size Codes HTML Font Style Codes HTML Bold/Italic Codes Combining Font Codes
Formatting Text
Formatting Text Intro Making Paragraphs Miscellaneous Formatting Headings & Subheadings Creating Hyperlinks
Using Graphics
Using Graphics on the Web Add Graphics to Your Pages Graphics and Accessibility How to Align Graphics Page Color & Background Graphics as Hyperlinks Horizontal Rules
Creating Tables
HTML Tables Tutorials HTML Table Fundamentals Background & Border Color Table Frames & Rules Table Width and Alignment Cells 1 -Space & Alignment Cells 2 -Row Column Span Cells 3 -Width & Height
Making Lists
HTML Lists Tutorials Bulleted Lists Numbered Lists Definition Lists
HTML Frames
HTML Frames Tutorials Using Frames for Layout Advanced Frame Layouts Putting Hyperlinks in Frames Frame Border Width Color, Margin and Control Problems with Frames SmartFrames: A Solution SSI: An Alternative to Frames
Web Page Forms
Making Feedback Forms A Simple Feedback Form Installing NMS FormMail Debugging Your Setup My Web Host is Out to Lunch User Input Components Text Fields Checkboxes & Radio Buttons Dropdown Menus Push Buttons Layout and Presentation
Basic CSS
Basic CSS Tutorials What is CSS? Why You Should Use CSS How to Use CSS Inline Styles Embedded Style Sheets External Style Sheets Class Selectors ID Selectors Combining Selectors
CSS Properties
CSS Properties Intro Font Styles Width, Height & Spacing Borders Backgrounds Position Float & Alignment Hyperlinks
All About Web Hosting
Hosting Your Own Website What is a Web Host? Your Website's Home Page Building a Website Offline About Free Web Hosting Best Free Web Hosting Commercial Web Hosting How to Get a Domain Name Ecommerce Web Hosting Web Hosting Terminology
Free Web Design Tools
Best Free Website Tools Best Free Text Editors Best Free Graphics Editors Free Website Analysis Tools
Setting Up HTML Kit
HTML Kit Introduction How to install HTML Kit Screenshot Breakdown Basic Configuration Overall Appearance Shortcuts and Startup Editing Window Customizing Toolbars Using the Favorites Tab Making a New Actions Bar Odds and Ends
Free Templates
Free Website Templates Two Column Fixed Width Three Column Liquid Layout Miscellaneous Templates Dynamic Menu Effects Two Column Experimental Terms of Use About These Templates
Website Templates Help
Getting Started Template Zip File Download How to Edit Your Template What to Edit in the HTML How to Add Your Logo Making a Website
Web Design Tips
Web Design Basics Tables vs. Tableless Using Tables for Layout Example Table Layouts World's Crappiest Web Page
Twitter Backgrounds
Twitter Backgrounds Intro Cool Twitter Backgrounds Cool Twitter Backgrounds 2 Plain Twitter Backgrounds Dark Twitter Backgrounds Best Twitter Backgrounds Cute Twitter Backgrounds Music Twitter Backgrounds Music Twitter Backgrounds 2 Twitter Backgrounds 101 TERMS OF USE
All About Web Browsers
What is a Web Browser? Mozilla Firefox Internet Explorer Opera How to Set Up Firefox Top 5 Firefox Extensions
 
Contact
Post Some Feedback Send Me An Email Iron Spider Blog About Iron Spider... Site Conventions
 
 
 

 

CSS Properties - Width, Height & Spacing

 
The CSS properties in the table below can be used to define widths, heights, padding and margin on various components on your web page. These properties are typically applied to block elements but you can also apply them to images and some form elements. These include the following:

body, p, div, blockquote, table, td, ul, ol, li, form, input, textarea, select, img


CSS Properties List 2 - Dimensions, Padding and Margin
Property NameSome Possible ValuesWhat It Does
width400px | 70%Sets width
height400px | 70%Sets height
padding10px | 5%Set padding on all 4 sides
padding-top10px | 5%Set padding on top
padding-bottom10px | 5%Set padding on bottom
padding-left10px | 5%Set padding on left side
padding-right10px | 5%Set padding on right side
margin20px | 7%Set margin on all 4 sides
margin-top20px | 7%Set margin on top
margin-bottom20px | 7%Set margin on bottom
margin-left20px | 7%Set margin on left side
margin-right20px | 7%Set margin on right side
(Please see Padding and Margin for more information about these properties.)

NOTES:
  • Pixels (px) ~ This sets a width, height, padding or margin in pixels. The syntax is any number followed by px.

    Examples:
    width: 400px;
    padding: 10px;

    Use pixels for measurements when you want to closely control the layout of your web page. (More about pixels...)
  • Percentage ~ This sets the width, height, padding or margin as a percentage of available space allotted to the element. The syntax is any number followed by the "%" sign.

    Examples:
    width: 50%;
    padding: 5%;

    Percentages are useful for creating a 'liquid display' which is a web page layout that expands and contracts according to the user's screen resolution. Percentages are also useful for applying widths and heights based on quick visual estimations of the available space for an element.

    SOME EXAMPLES »
    Below is an example of placing one div element inside of another. The outer div element (red border) has its width set to 400 pixels (400px). The inner div element (green border) has its width set to 50% hence its width becomes 200 pixels.

    width: 50%;

    If no width is specified, the div element will expand to take 100% of the available space. On the other hand, table elements will only take as much space as is required to display its content.

    The following examples will illustrate ~

    Below is a div element that has no width specified and that contains a single word "TESTING". Notice how it expands to take 100% of the available space:

    TESTING

    Below is a table element (one row, one cell) that has no width specified and contains a single word "TESTING". Notice how it only expands to provide just enough room for the content:

    TESTING

  • Padding ~ Here's the lowdown on the padding property. Instead of laboriously typing out all four properties, e.g., padding-top, padding-right, padding-bottom, padding-left, to set the padding on all four sides of your element, you can just use the padding shorthand property and a special syntax which will allow you to set the padding on all four sides at once.

    The following examples will illustrate how to use the special syntax:
    padding: 10px;
    All four sides = 10px each

    padding: 10px 20px;
    top & bottom = 10px each, left & right = 20px each

    padding: 10px 20px 15px;
    top = 10px, left & right = 20px each, bottom = 15px

    padding: 10px 20px 15px 5px
    top, right, bottom, left respectively
    (Easy reminder - Clockwise starting with top)
  • Margin ~ Here's what's going on with the margin property. Instead of laboriously typing out all four properties, e.g., margin-top, margin-right, margin-bottom, margin-left, to set the margin on all four sides of your element, you can just use the margin shorthand property and a special syntax which will allow you to set the margin on all four sides at once.

    Here's how to use the special syntax:
    margin: 10px;
    All four sides = 10px each

    margin: 10px 20px;
    top & bottom = 10px each, left & right = 20px each

    margin: 10px 20px 15px;
    top = 10px, left & right = 20px each, bottom = 15px

    margin: 10px 20px 15px 5px
    top, right, bottom, left respectively
    (Easy reminder - Clockwise starting with top)
  • Padding and Margin? ~ So now you may be thinking, yeah that's all very fine and well BUT... uhhhhh....

    ...Exactly what are padding and margin?

    Well quite simply, padding equals space between the content of a block element and its border. On the other hand, margin equals space surrounding a block element's border.

    The following color-coded example will illustrate:


    PADDING & MARGIN ILLUSTRATED
     
     
    It was a dark and stormy night. Blah blah blah etcetera... I'll just ramble on mindlessly to create some content in this block element for demonstrational purposes... How now brown cow... And so on and so forth...
     
     

    Legend

     
    =   Margin

     
    =   Border of block element

     
    =   Padding

     
    =   Content of block element

EXAMPLES:

Here's an example of an inline style applied to a paragraph tag using some of the CSS properties described above (dummy text is inserted for demonstrational purposes):


Example 1 - INLINE STYLE

<p style="width: 300px; margin-left: 100px;">Donec ut dolor. Nulla orci leo, facilisis in, ultrices in, viverra pretium, ligula. Donec suscipit. Cras vulputate. Donec vel neque. Integer nec nisl sed felis eleifend adipiscing. Suspendisse arcu magna, viverra eget, pretium vitae, iaculis ac, lorem. </p>



OR...

The same thing could be declared as an embedded stylesheet in the document head:


Example 2 - EMBEDDED STYLE SHEET

<style type="text/css">
<!--
p {
   width: 300px;
   margin-left: 100px;

}
-->
</style>



...and in the document body, you would simply put this:


<p>Donec ut dolor. Nulla orci leo, facilisis in, ultrices in, viverra pretium, ligula. Donec suscipit. Cras vulputate. Donec vel neque. Integer nec nisl sed felis eleifend adipiscing. Suspendisse arcu magna, viverra eget, pretium vitae, iaculis ac, lorem. </p>



Both Example 1 and Example 2 will produce the following effect which is a paragraph that is 300 pixels wide and has a left margin of 100 pixels:

Donec ut dolor. Nulla orci leo, facilisis in, ultrices in, viverra pretium, ligula. Donec suscipit. Cras vulputate. Donec vel neque. Integer nec nisl sed felis eleifend adipiscing. Suspendisse arcu magna, viverra eget, pretium vitae, iaculis ac, lorem.



*   *   *


Now if you're wondering how I drew the borders around the div elements used in the examples on this page, you can find out on the next page where we'll learn how to apply borders using CSS...






Best Free Stuff
for webmasters

Free Text Editors
Free Graphics Editors
Website Analysis Tools
Free Website Templates

See also:

Best Free Web Hosting
How to Make a Web Page

 

If you need a .COM web address, you can get one quick and easy at...

www.GoDaddy.com
<~ BACK TOP NEXT ~>
 
HTML Tutorials |  CSS Tutorials |  Web Hosting |  Domain Names |  Web Design Resources
Iron Spider © Copyright 2004-2011 Robert Darrell