I have some CSS that styles the marker next to a summary element within a details element. The CSS itself works fine. However, if I nest another details element within the first one (creating a parent details element and a child details element), my marker content doesn't toggle properly. As soon as I open the parent, the child marker shows as being open even though that element is not open yet.
I am not sure if there is a proper selector to isolate the child details element from the parent in this case since the child is not open and there is no [closed] syntax in CSS that I am aware of. It appears than when nesting details elements, once the parent is open, all children are also "open". Has anyone run into something like this before?
summary {
outline: none;
font-size: 1.15em;
}
summary::-webkit-details-marker {
display: none
}
summary:after {
background: #da291c;
border-color: #da291c;
border-radius: 15px;
content: "+";
color: #fff;
float: left;
font-size: 1em;
font-weight: bold;
margin: -2px 10px 0 0;
padding: 1px 0 3px 0;
text-align: center;
width: 30px;
}
details[open] summary:after {
content: "-";
}
<details>
<summary>Parent</summary>
<p>
Parent Holder Text
</p>
<details>
<summary>Child</summary>
<p>
Child Holder Text
</p>
</details>
</details>
Styling Details With CSS The <details> and <summary> elements can be styled just like any other block elements; select them through the element selector, a class, or an id and stack a pile of properties to style it.
The <summary> HTML element specifies a summary, caption, or legend for a <details> element's disclosure box. Clicking the <summary> element toggles the state of the parent <details> element open and closed.
The <summary> tag defines a visible heading for the <details> element. The heading can be clicked to view/hide the details. Note: The <summary> element should be the first child element of the <details> element.
The ::marker CSS pseudo-element selects the marker box of a list item, which typically contains a bullet or number. It works on any element or pseudo-element set to display: list-item , such as the <li> and <summary> elements.
Your CSS is applying content: "-";
to all summary:after
elements within details[open]
, so it cascades to children too. Try applying it to only direct children of the parent element with a child combinator (>
)
details[open] > summary:after {
content: "-";
}
details summary::-webkit-details-marker,
details summary::marker {
display: none;
content: "";
}
if it doesn't work try this (::marker and content for chrome)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With