Copied successfully!
Introduction to <div>
tag
The <div>tag in HTML, short for "division," is a versatile and commonly used element for grouping content on a webpage. It serves as a container that allows developers to organize and structure their HTML documents, making it easier to apply styles and manage content dynamically.
Copy to clipboard
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>title of <div> tag</title>
</head>
<body>
<divclass="container"data-info="Container: Main wrapper of the page">
<!-- Header Section -->
<divclass="header"data-info="Header: Website header area"> <h1>Website Header</h1>
</div> <!-- Main Content Section -->
<divclass="main-content clearfix"data-info="Main Content: Contains sidebar and main content"> <!-- Sidebar Section --> <divclass="sidebar"data-info="Sidebar: Sidebar area"> <h2>Sidebar</h2> <p>This is the sidebar content.</p> </div> <!-- Content Section --> <divclass="content"data-info="Content: Main content area"> <h2>Main Content</h2> <p>This is the main content area.</p> </div>
</div> <!-- Footer Section -->
<divclass="footer"data-info="Footer: Website footer area"> <p>Website Footer</p>
</div>
</div>
</body>
</html>
Copy to clipboard
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
.container {
width: 80%;
margin: 0 auto;
padding: 20px;
border: 2px solid #000; /* Outline for container */
background-color: #fff;
position: relative; /* For positioning hover information */
}
.header, .footer {
background-color: #e2e2e2;
text-align: center;
padding: 15px 0;
border: 1px solid #000; /* Outline for header and footer */
margin-bottom: 20px;
position: relative; /* For positioning hover information */
}
.main-content {
margin-bottom: 20px;
border: 1px solid #000; /* Outline for main content */
padding: 10px;
position: relative; /* For positioning hover information */
}
.sidebar {
float: right;
width: 30%;
padding: 10px;
background-color: #d9edf7;
border: 1px dashed #000; /* Dashed outline for sidebar */
position: relative; /* For positioning hover information */
}
.content {
width: 65%;
float: left;
padding: 10px;
background-color: #f5f5f5;
border: 1px dashed #000; /* Dashed outline for main content */
position: relative; /* For positioning hover information */
}
/* Tooltip Styling */
.header:hover::after,
.footer:hover::after,
.main-content:hover::after,
.sidebar:hover::after,
.content:hover::after,
.container:hover::after {
content: attr(data-info); /* Get the data-info attribute */
position: absolute;
top: -30px; /* Position above the hovered element */
left: 50%;
transform: translateX(-50%);
background-color: #333;
color: #fff;
padding: 5px 10px;
border-radius: 5px;
font-size: 12px;
white-space: nowrap; /* Prevent text from wrapping */
opacity: 0;
transition: opacity 0.3s; /* Smooth transition for appearance */
pointer-events: none; /* Prevent mouse events on tooltip */
}
/* Show tooltip on hover */
.header:hover::after,
.footer:hover::after,
.main-content:hover::after,
.sidebar:hover::after,
.content:hover::after,
.container:hover::after {
opacity: 1; /* Show tooltip */
}
.clearfix::after {
content: "";
display: table;
clear: both;
}
Global Attributes
Attributes | Description |
---|---|
accesskey | Specifies a shortcut key to activate or focus an element. |
autocapitalize | Controls whether and how text input is automatically capitalized. |
class | Specifies one or more class names for the element, allowing CSS styling and JavaScript manipulation. |
contenteditable | Specifies whether the content of an element is editable or not. |
contextmenu | Specifies a context menu for the element. |
dir | Defines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto". |
draggable | Specifies whether an element is draggable. Possible values are "true" or "false". |
enterkeyhint | Specifies the action label or icon to be shown for the enter key on virtual keyboards. |
hidden | Indicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set. |
id | Specifies a unique identifier for the element. |
inputmode | Provides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants. |
is | Allows you to specify the type of custom element. |
lang | Specifies the language of the element's content. |
nonce | A cryptographic nonce ("number used once") that can be used by Content Security Policy (CSP) to determine whether or not a given fetch will be allowed to proceed. |
part | Specifies the element’s part in the shadow DOM. |
slot | Assigns a slot in a shadow DOM shadow tree. |
spellcheck | Indicates whether the element is subject to spell checking. |
style | Provides inline CSS styling for the element. |
tabindex | Specifies the tab order of the element. |
title | Adds extra information about the element, displayed as a tooltip when hovering over the element. |
translate | Specifies whether the content of the element should be translated. Possible values are "yes" or "no". |
HTML Attributes | Global Attributes | Event Attributes |
---|---|---|
To view the full list | To view the full list | To view the full list |
elements | |||||
---|---|---|---|---|---|
<div> | Yes | Yes | Yes | Yes | Yes |
Improve Our Platform
Did you find what you were looking for?
Learn how to contribute.Last updated on by our contributors.
View this page on GitHub• Report an issue with this content