P粉7104549102023-08-03 16:12:52
If you were allowed to change the HTML a little, you could do this:
Copy the title to the previous sibling of <p>.
Hide it but keep its width using visibility:hidden;
Wrap repeated headings and paragraphs with <div>.
Use the grid.
Delete mark.
summary, div { display: grid; grid-template-columns: auto 1fr; } .visibility-hidden { visibility: hidden; } /* Hide marker */ details > summary { list-style: none; } details > summary::-webkit-details-marker { display: none; }
<details> <summary> <span class="left">Variable Length Title:</span> <span class="right"> A sentence worth of text that may or may not wrap depending upon the width of the container. </span> </summary> <div> <span class="visibility-hidden">Variable Length Title:</span> <p> This is the text that is not in the summary tag but still is in the details tag therefore hidden unless clicked on. </p> </div> </details>