You may often see the following effect: That’s right, it’s the commonly used “expand and collapse” interaction form on the page. The usual practice is to control the display attribute value to switch between none and other values. However, although the function can be realized, the effect is very stiff, so there is such a requirement - it is hoped that the element can have an obvious height sliding effect when expanding and collapsing. The previous implementation could use jQuery's My first reaction was to use However,
Therefore, to achieve the effect of the beginning of the article, the author recommends the max-height attribute: <div class="accordion"> <input id="collapse1" type="radio" name="tap-input" hidden /> <input id="collapse2" type="radio" name="tap-input" hidden /> <input id="collapse3" type="radio" name="tap-input" hidden /> <article> <label for="collapse1">List 1</label> <p>Content 1<br>Content 2<br>Content 3<br>Content 4</p> </article> <article> <label for="collapse2">List 2</label> <p>Content 1<br>Content 2<br>Content 3<br>Content 4</p> </article> <article> <label for="collapse3">List 3</label> <p>Content 1<br>Content 2<br>Content 3<br>Content 4</p> </article> </div> .accordion { width: 300px; } .accordion article { cursor: pointer; } label { display: block; padding: 0 20px; height: 40px; background-color: #f66; cursor: pointer; line-height: 40px; font-size: 16px; color: #fff; } p { overflow: hidden; padding: 0 20px; margin: 0; border: 1px solid #f66; border-top: none; border-bottom-width: 0; max-height: 0; line-height: 30px; transition: all .5s ease; } input:nth-child(1):checked ~ article:nth-of-type(1) p, input:nth-child(2):checked ~ article:nth-of-type(2) p, input:nth-child(3):checked ~ article:nth-of-type(3) p { border-bottom-width: 1px; max-height: 130px; } In CSS,
There is another way to show the pulling effect: Its characteristic is that when the mouse hovers over a part of the component, the part will expand and squeeze the adjacent parts, and return to its original state when the mouse leaves. If you move the mouse quickly over it, it will produce an accordion effect. To achieve the accordion effect using JS, you must monitor li { } li:hover { } As for layout, if you want to expand and shrink elements arranged in a row with the same/different widths within a row, a better way is flex ! <ul class="accordion"> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> .accordion { display: flex; width: 600px; height: 200px; } li { flex: 1; cursor: pointer; transition: all 300ms; } li:nth-child(1) { background-color: #f66; } li:nth-child(2) { background-color: #66f; } li:nth-child(3) { background-color: #f90; } li:nth-child(4) { background-color: #09f; } li:nth-child(5) { background-color: #9c3; } li:nth-child(6) { background-color: #3c9; } li:hover { flex: 2; background-color: #ccc; }
This is the end of this article about how to achieve the list pull-down effect on the page with pure CSS. For more relevant CSS page list pull-down content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope that everyone will support 123WORDPRESS.COM in the future! |
<<: Analyzing ab performance test results under Apache
When newbies develop div+css, they need to name t...
<br />Previous article: Web Design Tutorial ...
Many friends have asked in forums and message are...
1. Installation Package MYSQL service download ad...
ARGB is a color mode, which is the RGB color mode...
1. Import the module and define a validation stat...
CentOS 8 is officially released! CentOS fully com...
Table of contents 1. What is redux? 2. The princi...
Table of contents Packaging, launching and optimi...
This article shares with you how to use canvas an...
Publish Over SSH Plugin Usage Before using Publis...
When a company builds Docker automated deployment...
Table of contents Introduction to Anaconda 1. Dow...
Docker is really cool, especially because it'...
Table of contents 01. Listener watch (1) Function...