Home>

I would like to prepare two details and set different images for each summary
I couldn't do it with the code below
How can I write different images?
Would you please tell me the details?

Writing code that was useless
summary: parent1: before {
  content: url ("image for parent 1");
  width: 16px;
  height: 16px;
  background-color: deepskyblue;
}
summary: parent2: before {
  content: url ("image for parent 2");
  width: 16px;
  height: 16px;
  background-color: deepskyblue;
}
<details>
<summary>Parent 1</summary><!-I want to set the image of this part individually->


<details>
<summary>Child 1</summary>
hello
</details>
</details>

<details>
<summary>Parent 2</summary><!-I want to set the image of this part individually->


<details>
<summary>Child 2</summary>
hello
</details>
</details>
<style>
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 {
  content: url ("image for parent 1");
  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;
  }
}
</style>
  • Answer # 1

    summary: parent1: before {
    Corrected the above to below
    summary.parent1: before {

    The class selector is before the class name..Attach.

    parent2Similarly.

  • Answer # 2

    Is it something like this?

    .parent1:: before {
        content: url ("image1.gif");
    }
    .parent2 :: before {
        content: url ("image2.gif");
    }