Resources | Subject Notes | Information Communication Technology ICT
The
The
Syntax: <div class="class-name" id="element-id"> <content> </div>
Classes allow you to apply the same set of styles to multiple elements. You define a class in the <style>
section or in an external CSS file, and then apply it to HTML elements using the class
attribute.
Example:
<div class="container"> <h2>Welcome</h2> <p>This is some text within a container.</p> </div>
Styles can be applied to elements in several ways: inline styles (directly within the HTML tag), internal styles (within the <style>
tag in the <head>
section), or external stylesheets (linked using the <link>
tag).
Example of an internal style:
<style> .container { border: 1px solid black; padding: 10px; background-color: #f0f0f0; } h2 { color: blue; } </style>
The
Example of a simple layout:
Section | Description |
---|---|
Header | The top section of the webpage. |
Main Content | The primary content of the webpage. |
Footer | The bottom section of the webpage, often containing copyright information. |
<!DOCTYPE html> <html> <head> <title>Div Tag Example</title> <style> .highlight { background-color: yellow; font-weight: bold; } .important { color: red; } </style> </head> <body> <div class="container"> <h1>My Website</h1> <div class="highlight"> <p>This is a highlighted paragraph.</p> </div> <div class="important"> <p>This is an important paragraph.</p> </div> <ul> <ol> <li>First item</li> <li>Second item</li> <li>Third item</li> </ol> </ul> </div> </body> </html>