Is it possible to customize the style of HTML detail tags in this way?
P粉300541798
P粉300541798 2023-08-02 18:34:52
0
1
472
<p>这就是我想要达到的目标,</p> <pre class="brush:php;toolbar:false;">> Variable Length Title: A sentence worth of text that may or may not wrap depending upon the width of the container. This is the text that is not in the summary tag but still is in the details tag therefore hidden unless clicked on.</pre> <p>html看起来像这样,</p> <pre class="lang-html prettyprint-override"><code><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> <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> </details> </code></pre> <p>我能想到的一个不太优雅的解决方案是通过display: inline-block;并为细节p留下填充,但这仍然给我留下了文本换行的问题,换行的文本从一行的开头开始。<br /><br />如果可能的话,我正在寻找CSS唯一的解决方案。</p><p><br /></p>
P粉300541798
P粉300541798

reply all(1)
P粉710454910

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>


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template