css - 如何设置<details>和<summary>的样式?

标签 css pseudo-element markers

刚刚发现标签。默认 给出了非常粗糙的样式。我成功使用 ::marker 伪元素 删除默认标记,但不知道如何将其放在右侧。使用了 ::after 伪元素,但当摘要“打开”时无法为其设置动画(旋转 180 度或缩放)。有正确的方法吗?或者我的方法错过了什么?谢谢。

PS:由于我是新手,我不知道如何将Google图标字体获取到codepen。不过,您将看到我尝试对 Expand_arrow 图标执行的操作。

* {
  box-sizing: border-box;
  margin: 0px;
  padding: 0px;
}

.thing {
  background-color: cadetblue;
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.new_game {
  font-size: 3rem;
}

.what_is_question {
  background-color: cornflowerblue;
  cursor: pointer;
}

.what_is_question[open] {
  background-color: darkmagenta;
}

.what_is_question {
  font-size: 5rem;
}

.question_title {
  position: relative;
}

.question_title::after {
  content: url(./images/expand_more_black_24dp.svg);
}

.what_is_question[open] .question_title::after {
  transform: rotate(180deg);
}

.question_title::marker {
  content: none;
}

.answer {
  background-color: darkkhaki;
  font-size: 3rem;
  padding-left: 3.5%;
}
<div class="thing">
  <h1 class="new_game">QnA</h1>
  <details class="what_is_question">
    <summary class="question_title">What is the question?</summary>
    <p class="answer">The question is the answer.</p>
  </details>
</div>

https://codepen.io/consig1iere/pen/bGWXRMW

最佳答案

问题是您无法将 transforms 应用于具有 display: inline 的元素。

因此,将 display: inline-block; 添加到您的 .question-title

.what_is_question[open] .question_title::after {
  display: inline-block;
  transform: rotate(180deg);
}

关于css - 如何设置<details>和<summary>的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69055858/

相关文章:

javascript - 使文本输入看不见但有形

html - CSS:Scale(x) 使图标旋转

css - 在 IE 中对 css 生成的内容应用文本装饰

javascript - 使用传单获取 geojson 大陆/国家/州的中心

python - 如何从头开始制作彩色标记图例

html - 水平到垂直菜单,在浏览器窗口调整大小

CSS一条有2种不同颜色的直线水平线

css - 如何将伪元素固定在滚动元素中?

javascript - 使用 OpenLayers,删除标记层和弹出窗口的正确方法是什么?

html - tailwindcss 警报悬停在固定导航上