【问题标题】:Can you set the details element to display grid?您可以将详细信息元素设置为显示网格吗?
【发布时间】:2021-08-20 17:52:44
【问题描述】:

我想创建一个可以使用<details> 元素折叠的过滤器元素,因为它具有open/close 功能。

但是,当涉及到内部字段的样式时,我想使用网格,似乎 <details> 不能设置为 display: grid

有人遇到过这种行为吗?

非常感谢您的意见!

details {
  display: grid;
  grid-template-columns: 100px 100px;
}

input {
  width: 100%;
}

label {
  display: block;
}

label:first-of-type {
  color: red;
  grid-column: 1;
}

label:last-of-type {
  color: blue;
  grid-column: 2;
}
<form>
  <details open>
    <summary>Filter</summary>
    <label>
        I should be on the left
        <input type="text">
      </label>
    <label>
        I should be on the right
        <input type="text">
      </label>
  </details>
</form>

Codepen here!

【问题讨论】:

  • 确实,很奇怪。是否可以选择将您想要网格对齐的元素放在设置为显示的容器中:网格?
  • 我认为这是我必须走的路线。我在详细信息中添加了一个 div,这似乎有效。

标签: css css-grid details-tag


【解决方案1】:

必须将input 的表单封装在&lt;div&gt; 或其他容器中的详细信息中,以使display: grid 工作和设置样式。

【讨论】:

    猜你喜欢
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 2018-07-31
    • 2012-03-29
    • 1970-01-01
    相关资源
    最近更新 更多