Home >Web Front-end >HTML Tutorial >Attributes of div tags in html

Attributes of div tags in html

下次还敢
下次还敢Original
2024-04-27 21:18:32603browse

Div tag is a block-level element used to create or divide page areas. Its attributes include: general attributes: id, class content attributes: align, style layout attributes: width, height, padding, margin and others. Attributes: lang, dir, title, data-*

Attributes of div tags in html

#Div tag attributes

div tag is in HTML A block-level element used to create or divide areas on the page. It has the following attributes:

Common attributes

  • id: Specifies the unique identifier of the div element.
  • class: Add one or more class names to the div element to apply CSS styles.

Content attributes

  • align: Set the alignment of the content in the div element, such as left, right, center.
  • style: Set the style of the div element inline, including color, font, background, etc.

Layout properties

  • width: Set the width of the div element.
  • height: Set the height of the div element.
  • padding: Adds space between the inner edge of a div element and its content.
  • margin: Adds space between the outer edge of a div element and adjacent elements.

Other attributes

  • lang: Specify the language of the content in the div element.
  • dir: Specify the text direction of the content in the div element, such as ltr (left to right) or rtl (right to left).
  • title: Provides a tooltip text for the div element.
  • data-*: Custom data attributes used to store data related to div elements.

Example

<code class="html"><div id="myDiv" class="container" style="width: 500px; height: 300px; padding: 10px;">
  <h1>标题</h1>
  <p>段落</p>
</div></code>

In this example, the div element has the following attributes:

  • id="myDiv": unique Identifier
  • class="container": a class name
  • style="...": inline style, including width, height and padding
  • data-* attributes are used to store custom data

The above is the detailed content of Attributes of div tags in html. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn