Home > Web Front-end > CSS Tutorial > How Can I Create Collapsible DIVs with Pure HTML and CSS?

How Can I Create Collapsible DIVs with Pure HTML and CSS?

Linda Hamilton
Release: 2024-12-06 15:02:12
Original
975 people have browsed it

How Can I Create Collapsible DIVs with Pure HTML and CSS?

Collapsible DIVs Using HTML, CSS

Seeking a method to create hideable and collapsible DIV elements without relying on jQuery? This issue often arises in mobile website design, particularly when offline access is crucial. Using pure HTML and CSS, achieving this functionality is possible.

Solution:

Using HTML5's

and tags is a viable solution:

<details>
  <summary>Collapse 1</summary>
  <p>Content 1...</p>
</details>
<details>
  <summary>Collapse 2</summary>
  <p>Content 2...</p>
</details>
Copy after login

This approach leverages HTML5's native functionality without the need for additional JavaScript or CSS styling. The

tag represents a collapsible container, while the tag defines its interactive header. Clicking on the tag toggles the visibility of the content within the
tag.

The above is the detailed content of How Can I Create Collapsible DIVs with Pure HTML and CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template