Set padding for four directions separately in HTML and CSS
Description
The following code shows how to set padding for four directions separately.
Example
<!-- w w w . j a v a 2 s .com-->
<html>
<head>
<title>padding</title>
<style type='text/css'>
div {
float: left;
background: gold;
margin: 5px;
width: 250px;
}
div div {
float: none;
background: white;
border: none;
font: 10px sans-serif;
color: rgb(200, 200, 200);
width: auto;
}
div#properties {
padding-top: 2px;
padding-right: 4px;
padding-bottom: 6px;
padding-left: 8px;
}
div#four-values { padding: 2px 4px 6px 8px; }
div#three-values { padding: 2px 8px 6px; }
div#two-values { padding: 2px 8px; }
div#one-value { padding: 2px; }
</style>
</head>
<body>
<div id='properties'>
<div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Nulla bibendum eros sit amet lectus. Nunc eros massa,
interdum ut, congue ut, scelerisque quis, tellus.
</div>
</div>
<div id='four-values'>
<div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Nulla bibendum eros sit amet lectus. Nunc eros massa,
interdum ut, congue ut, scelerisque quis, tellus.
</div>
</div>
<div id='three-values'>
<div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Nulla bibendum eros sit amet lectus. Nunc eros massa,
interdum ut, congue ut, scelerisque quis, tellus.
</div>
</div>
<div id='two-values'>
<div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Nulla bibendum eros sit amet lectus. Nunc eros massa,
interdum ut, congue ut, scelerisque quis, tellus.
</div>
</div>
<div id='one-value'>
<div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Nulla bibendum eros sit amet lectus. Nunc eros massa,
interdum ut, congue ut, scelerisque quis, tellus.
</div>
</div>
</body>
</html>
The code above generates the following result.
HTML CSS Tutorial Padding
Combine negative text-indent and padding-le...
Compare padding, one value, two values, thr...
Demonstrate padding 0 is the default in HTM...
Demonstrate that the element's background i...
Do padding with em value in HTML and CSS
Set padding-left to 1.5em in HTML and CSS
Set padding-left to 1cm and padding-right t...
Set padding-top to 2px in HTML and CSS
Combine negative text-indent and padding-le...
Compare padding, one value, two values, thr...
Demonstrate padding 0 is the default in HTM...
Demonstrate that the element's background i...
Do padding with em value in HTML and CSS
Set padding for four directions separately ...
Set padding-left to 0px for list in HTML an...Set padding-left to 1.5em in HTML and CSS
Set padding-left to 1cm and padding-right t...
Set padding-top to 2px in HTML and CSS