CSS3 Padding and Margin Coding
CSS3 Basics - Part 12
Forward: In this part of the series we see how to code padding and margin strips in CSS3.
By: Chrysanthus Date Published: 23 Jul 2012
Introduction
Note: If you cannot see any text or if you think anything is missing (missing code, missing image, broken link, etc.) just contact me at forchatrans@yahoo.com.
Giving or Changing the Padding Width of an HTML Element
The syntax to give and/or change the four (top, right, bottom, and left) paddings is:
padding: number and units
This means that whether or not any padding existed, this syntax would give the element the new padding of the value (number) quoted.
The unit can be px (for pixel) or %. If it is %, then it is relative to the width of the containing element that has the element in question. Read and try the following code where the width of the 4 paddings is 75px for the div element:
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
div {padding:75px; width:50%; border-color:blue; border-style:solid; border-width:2px}
</style>
</head>
<body>
<div>
This is the DIV element with 75px padding. This is the DIV element with 75px padding. This is the DIV element with 75px padding. This is the DIV element with 75px padding. This is the DIV element with 75px padding.
</div>
</body>
</html>
The property and value for the padding in the above code is:
padding:75px;
The syntax to give and/or change the 4 margins is:
margin: number and units
The unit can be px (for pixel) or %. If it is %, then it is relative to the width of the containing element that has the element in question. Read and try the following code where the width of the 4 margins is 10% for the div element:
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
div {padding:75px; margin:10%; width:50%; border-color:blue; border-style:solid; border-width:2px}
</style>
</head>
<body>
<div>
This is the DIV element with 75px padding. This is the DIV element with 75px padding. This is the DIV element with 75px padding. This is the DIV element with 75px padding. This is the DIV element with 75px padding.
</div>
</body>
</html>
The property and value for the margin in the above code is:
margin:10%;
That is it, for this part of the series. We continue in the next part.
Chrys
Related Links
Major in Website DesignWeb Development Course
HTML Course
CSS Course
ECMAScript Course
NEXT