The box model and padding - HTML & CSS
by danielkwood
HTML
<html>
<head>
<title>Box model</title>
<link rel="stylesheet" href="theme.css" type="text/css"/>
</head>
<body>
<h1>This is a heading</h1>
<h2>This is smaller heading</h2>
<h3>This is an even smaller heading</h3>
<p>And this is a paragraph</p>
<img src="image.png" width="30%"/>
</body>
</html>
CSS
body{
font-family: Arial;
}
h1{
background-color: yellow;
padding: 20px; /* padding on all four sides */
}
h2{
background-color: green;
padding-top: 30px;
padding-right: 20px;
padding-bottom: 50px;
padding-left: 30px;
}
h3{
background-color: orange;
padding: 10px 20px 10px 20px; /* top, right, bottom, left */
}
p{
background-color: lightblue;
padding: 10px 30px; /* top and bottom, right and left */
}
img{
padding: 5%; /* you can also use % values */
}