When details are nested, CSS settings such as hover of nested details are not effective.

If i click or hover the parent, the CSS will be applied to the parent,
CSS hover etc. will be invalid for the child at all

If i know how to solve this problem, could you please tell me?

<summary>Parent 1</summary>

<details><!-Invalid parts such as hover->
<summary>Child 1</summary>

<summary>Parent 2</summary>

<details><!-Invalid parts such as hover->
<summary>Child 2</summary>
body, html {
  height: 100%;
summary {
  position: relative;
  display: block;/* Remove the arrow * /
  padding: 10px 10px 10px 30px;/* Open the margin of the icon * /
  cursor: pointer;/* Cursor to pointer * /
  font-weight: bold;
  background-color: green;
  transition: 0.2s;
summary: hover {
  background-color: skyblue;
summary ::-webkit-details-marker {
  display: none;/* Erase the arrow * /
/ * Display icon with pseudo element * /
summary: before,
summary: after {
  content: "";
  margin: auto 0 auto 10px;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
summary: before {
  width: 16px;
  height: 16px;
  background-color: deepskyblue;
summary: after {
  left: 6px;
  width: 5px;
  height: 5px;
  border: 4px solid transparent;
  border-left: 5px solid white;
  box-sizing: border-box;
  transition: .1s;
/ * Open style * /
details [open] summary {
  background-color: yellow;
details [open] summary: after {
  transform: rotate (90deg);/* Rotate the icon * /
  left: 4px;/* Adjust position * /
  top: 5px;/* Adjust position * /
/ * Animation * /
details [open] .details-content {
  animation: fadeIn 0.5s ease;
@keyframes fadeIn {
  0% {
    opacity: 0;
    transform: translateY (-10px);
  100% {
    opacity: 1;
    transform: none;
  • Answer # 1

    Selectordetails [open] summaryIf you separate it with a half-width space, it will be a descendant element.summaryApplies to all.
    details [open] summaryWhensummary: hoverThen, the former is more detailed, so if the parent element is open, the former will take precedence.

    If you want to limit to the child elements directly belowdetails [open]>summaryPlease.

    Child Joiner-CSS: Cascading Stylesheet | MDN

  • Answer # 2

    The summary style at the time of opening, in that it remains yellow at the time of opening and does not change color when hovering.background-color: yellow;Is prioritized.

    details [open] summary: hover {
        background-color: skyblue;