Make details and summary Elements that Look Like a Button
I'm working on a bitty script to automatically add "Alt Text" buttons under my images. I'm using elements for the native behavior. The child elements are blocks by default. I'm making them inline-block so the look more like buttons.
Here's the CSS I ended up with that expands the summary back out when the parent element is open.
Output
Click Me
This is the contents of the details element
HTML
Click Me
This is the contents of the details element
CSS
) }
}
}
}
& }
}
}
& }
}
I've played around with a few iterations where the is styled in different ways when the <details> is open. I'm quite happy with the way this one looks.
-a
Endnotes
I had to put the disclosure arrows in with :before pseudo-elements when I switched the summary to inline-block. I wouldn't have thought that to be necessary. Not a big deal.
I'm using [open] instead of :open because the later is marked as not fully working in safari yet.