0

I have this CSS / HTML code :

    body {
        font-family: "Segoe UI", "Helvetica Neue", "Helvetica", "Open Sans", "FreeSans", "Arial", "sans-serif";
        margin: 2em 1em 5em 1em;
    }
    ul {
        margin-top: 0px;
    }
    details {
        margin-bottom: 1.3em;
    }
    details summary {
        font-size: 1.1em;
        font-weight: bold;
        display: inline;
        cursor: pointer;
    }
    details summary ~ * {
        animation: expanddetails 0.3s ease-out;
        transform-origin: left top;
    }
    @keyframes expanddetails {
        0% {
            opacity: 0;
            line-height: 0%;
            transform: scaleY(0%);
        }
        25% {
            opacity: 0.5;
            line-height: 25%;
            transform: scaleY(25%);
        }
        100% {
            opacity: 1;
            line-height: 100%;
            transform: scaleY(100%);
        }
    }
    summary::marker, summary::-webkit-details-marker {
        content: none;
    }
    summary::after {
        content: "+";
        display: inline-block;
        transition: 0.3s;
        transform: rotate(0);
    }
    details[open] summary::after {
        content: "+";
        transform: rotate(360deg);
    }
    h2 {
        font-size: 1.1em;
        margin-bottom: 0;
    }
    .nobullet {
        list-style: none;
    }
            <div>
                <p>Some text before inside div</p>
            </div>
            <details>
                <summary>Summary 1 &nbsp;&nbsp;</summary>
                <ul>
                    <li>List 1 - Item 1</li>
                    <li>List 1 - Item 2</li>
                    <li class="nobullet">See <a href="#myid"><strong>There</strong></a>, ...</li>
                </ul>
            </details>
            <details>
                <summary>Summary 2 &nbsp;&nbsp;</summary>
                <ul>
                    <li>List 2 - Item 1</li>
                    <li>List 2 - Item 2</li>
                    <li>List 2 - Item 3</li>
                    <li class="nobullet">...</li>
                </ul>
            </details>
            <details>
                <summary>Summary 3 &nbsp;&nbsp;</summary>
                <ul>
                    <li>List 3 - Item 1</li>
                    <li>List 3 - Item </li>
                </ul>
            </details>
            <details>
                <summary>Summary 4 &nbsp;&nbsp;</summary>
                <ul id="myid">
                    <li>List 4 - Item 1</li>
                    <li>List 4 - Item 2</li>
                    <li class="nobullet">...</li>
                </ul>
            </details>
            <h2>Some Element with no list</h2>
            <div>
                <p>Other text</p>
            </div>

EDIT 2

The animation for the expansion of the detail elements works once only for each element, except on Firefox (always working). Furthermore, it is triggered on expand only, not when collapsing, while the "+" sign is rotating on expand and collpase and for each expand/collpase not only once. Why ? and how can this works each time, and for collapsing too.

One more question : is there a way without javscript to expand summary 4 on anchor click (this don't work for Firefox).

Thanks

CFou
  • 978
  • 3
  • 13
  • I can't see the animation on `summary 1`. – Ahmed Ali Jan 25 '23 at 17:31
  • I've run this code locally, but it doesn't even work. – Ahmed Ali Jan 25 '23 at 17:36
  • Indeed, But could you try to create [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Ahmed Ali Jan 25 '23 at 17:56
  • Does this answer your question? [How To Add CSS3 Transition With HTML5 details/summary tag reveal?](https://stackoverflow.com/questions/38213329/how-to-add-css3-transition-with-html5-details-summary-tag-reveal) – Ahmed Ali Jan 25 '23 at 18:40

0 Answers0