css - 单击列表并展开一个框

标签 css flexbox

我有一个元素列表,每个列表都包含一个默认情况下隐藏的框,点击每个列表后应该显示该框。

现在的问题是展开一个列表后,其他列表项也会展开。

请查看图片:enter image description here

有什么办法可以只展开被点击的元素吗?

<li>
  user name test
  <div class="content">
    <span>
      A card can be used to display content related to 
      a single subject. The content can consist of multiple 
      elements of varying types and sizes.
    </span>
  </div>
</li>
<li>
  user name test
  <div class="content">
    <span>
      A card can be used to display content related to 
      a single subject. The content can consist of multiple 
      elements of varying types and sizes.
    </span>
  </div>
</li>

fiddle :http://jsfiddle.net/8qLt3wru/4/

最佳答案

一个解决方法是使用 HTML <details>披露和 CSS 是这样的:

details {
  float:left;
  width: 50%;
    display:flex;
  flex-wrap:wrap;
}
<details>
    <summary>Details</summary>
    This is an example of the details disclosure.
</details>
<details>
    <summary>Details</summary>
    This is an example of the details disclosure.
</details>
来源:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details

关于css - 单击列表并展开一个框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59503745/

相关文章:

html - 如何使用flexbox对齐一些 block

php - IE 中的 div 列表对齐问题

javascript - TweenMax at function out - 如何实现条件?

jquery - 与加载图像相同的容器宽度和高度

html - 带显示屏的按钮 :block not stretched

html - 我不明白为什么在 flexbox 中我的图像下方有一个空白区域

javascript - w3schools 模态动画关闭

HTML CSS响应浏览器大小的变化位置

html - 具有可调整大小图像的 flexbox 列

css - safari:flexbox 和 extra margin