Introducción:
A veces tenemos mucho contenido para mostrar y para que el sitio web se vea bonito y corto, usamos los cuadros de texto plegables. Los cuadros de texto plegables son esa división que es la combinación de encabezado y contenido, generalmente solo el encabezado es visible, pero cuando se presiona, se muestra el contenido.
Configuración:
- Tienes que importar el componente amp-accordion en tu encabezado para usar esta etiqueta.
<script async custom-element="amp-accordion" src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js"> </script>
- Para hacer un acordeón anidado, use el código mencionado a continuación:
<amp-accordion class="sample" disable-session-states> <section> <amp-accordion class="nested-accordion"> <section> <h4>Nested Section 1</h4> <p>content</p> </section> <section> <h4>Nested Section 2</h4> <p>content</p> </section> </amp-accordion> </section> </amp-accordion>
Ejemplo:
<!DOCTYPE html> <html <img draggable="false" class="emoji" alt="" s rc="https://s.w.org/images/core/emoji/11/svg/26a1.svg"> <head> <meta charset="utf-8" /> <script async src= "https://cdn.ampproject.org/v0.js"> </script> <script async custom-element="amp-accordion" src= "https://cdn.ampproject.org/v0/amp-accordion-0.1.js"> </script> <link rel="canonical" href= "https://amp.dev/documentation/examples/components/amp-accordion/index.html" /> <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1" /> <style amp-boilerplate> body { -webkit-animation: -amp-start 8s steps(1, end) 0s 1 normal both; -moz-animation: -amp-start 8s steps(1, end) 0s 1 normal both; -ms-animation: -amp-start 8s steps(1, end) 0s 1 normal both; animation: -amp-start 8s steps(1, end) 0s 1 normal both; } @-webkit-keyframes -amp-start { from { visibility: hidden; } to { visibility: visible; } } @-moz-keyframes -amp-start { from { visibility: hidden; } to { visibility: visible; } } @-ms-keyframes -amp-start { from { visibility: hidden; } to { visibility: visible; } } @-o-keyframes -amp-start { from { visibility: hidden; } to { visibility: visible; } } @keyframes -amp-start { from { visibility: hidden; } to { visibility: visible; } } </style> <noscript> <style amp-boilerplate> body { -webkit-animation: none; -moz-animation: none; -ms-animation: none; animation: none; } </style> </noscript> <style amp-custom> amp-accordion section[expanded] .show-more { display: none; } .nested-accordion h4 { font-size: 14px; background-color: #ddd; } amp-accordion.hidden-header section[expanded] h4 { border: none; } /* these styles are not required for the samples to work */ :root { --space-2: 1rem; /* 16px */ } amp-accordion.sample { margin: var(--space-2); } h1, h4 { color: forestgreen; } section { color: crimson; } </style> <meta name="robots" content="noindex, nofollow" /> </head> <body> <center> <h1> Geeks For Geeks </h1> </center> <amp-accordion class="sample" disable-session-states> <section> <h4>Section 1</h4> <p>GeeksforGeeks is a Computer Science portal for geeks.</p> </section> <section> <h4>Section 2</h4> <amp-accordion class="nested-accordion"> <section> <h4>Nested Section 2.1</h4> <p>GeeksforGeeks is a Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes etc.</p> </section> <section> <h4>Nested Section 2.2</h4> <p>GeeksforGeeks is a Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes etc.</p> </section> </amp-accordion> </section> </amp-accordion> </body> </html>
Producción:
Publicación traducida automáticamente
Artículo escrito por aditya_taparia y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA