Property Name | Some Possible Values | What It Does |
---|---|---|
width | 400px | 70% | Sets width |
height | 400px | 70% | Sets height |
padding | 10px | 5% | Set padding on all 4 sides |
padding-top | 10px | 5% | Set padding on top |
padding-bottom | 10px | 5% | Set padding on bottom |
padding-left | 10px | 5% | Set padding on left side |
padding-right | 10px | 5% | Set padding on right side |
margin | 20px | 7% | Set margin on all 4 sides |
margin-top | 20px | 7% | Set margin on top |
margin-bottom | 20px | 7% | Set margin on bottom |
margin-left | 20px | 7% | Set margin on left side |
margin-right | 20px | 7% | Set margin on right side |
(Please see Padding and Margin for more information about these properties.)
px
. width: 400px;
padding: 10px;
width: 50%;
padding: 5%;
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. 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. 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: 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
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.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
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.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)
<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>
<style type="text/css">
<!--
p {
width: 300px;
margin-left: 100px;
}
-->
</style>
<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>
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.
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...
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...
<~ BACK | TOP | NEXT ~> |