- 1). Open your HTML document in an editor, such as Windows Notepad.
- 2). Create the CSS code for margins by adding the following code within the <head> section of your HTML file:
.mymargin { margin: 50px 0px 0px 40px; }
The "." character at the beginning of the line indicates a class selector, which can be used on multiple elements. The "margin" property will set a 50px margin on the top, a 0px margin on the right, a 0px margin on the bottom and a 40px margin to the left of the element. - 3). Add the following the HTML code within the <body> section of your file:
<p>First paragraph.</p>
<p class="mymargin">Second paragraph.</p>
This creates 50px of empty space between the two paragraphs vertically. It also sets 50px of space between the second paragraph and the left side of the page. - 4). Save the HTML file and upload it to your Web server. Refresh the page to view the new margins.
previous post