The Div Tag
The <div>
tag is an HTML tag that stands for Division, and is used for dividing up sections of your page. This can be used to create a specific section of your page or to create a box around the whole page (similar to how we used tables for that).
The <div>
tag works with both CSS classes and IDs, and needs to be closed. It also can have inline styles added to it. The most common uses for the div tag are to break the page into sections. For example, your page might have a div for a header, another div for the navbar, another div for the main content, and another div for the footer.
The CSS Box Model
The box model is key in understanding how the margins, borders, and padding are applied to the content. Look at this model. The inside is the content, where all your text or images are. The padding is applied before the border, and lasting the margin affects the outermost area.
Example 1a – The CSS Code |
|
Example 1b – The HTML Code |
|
From the example, we can see that the div tag is using the class from the CSS called reddashed and the main content is using a div to call the ID from the CSS.
Practice:
|