The community member is working on a website and wants to create an "about" section with a "read more" button that expands the text to show the full content. The comments suggest using a collapsible component, but the community member had trouble dynamically updating the button text to say "read less" when the text is fully shown. Some community members provided code examples using JavaScript and CSS to achieve the desired functionality, including a link to a CSS-only solution and a checkbox-based approach. There is no explicitly marked answer.
Pls I'm working on a site, I want to have an about section that shows a bit of text with a read more button that expands the text to show the whole content. How do I go about this?
Yeah I tried that and kind of maneuvered it to work but I couldn't edit the button content text dynamically. I wanted the button to read "read more" when the text is collapsed and "read less" or "close" when the text is fully showing
body:has([type=checkbox]:checked) p {
display: none;
}
Add a reply
Sign up and join the conversation on Discord
","dateCreated":"2025-03-03T21:29:59.489Z","dateModified":"2025-03-03T21:34:02.349Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/6c66325d-fff8-43a2-b97e-549275813461","name":"Jeremy","identifier":"6c66325d-fff8-43a2-b97e-549275813461","image":"https://cdn.discordapp.com/avatars/383871071566430208/6de448190b31c7a9af49e5fbd4f5d047.webp?size=256"},"commentCount":0,"comment":[],"position":5,"upvoteCount":0},{"@type":"Comment","text":"Just thinking about it, you could probably do this with CSS only. I haven't verified it, but it seems plausible. Add 2 different buttons, \"read more\" and \"read less\" with IDs attached to each. Then add CSS to display each based on the data-state:eg:","dateCreated":"2025-03-03T21:37:39.257Z","dateModified":"2025-03-03T21:37:39.257Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/6c66325d-fff8-43a2-b97e-549275813461","name":"Jeremy","identifier":"6c66325d-fff8-43a2-b97e-549275813461","image":"https://cdn.discordapp.com/avatars/383871071566430208/6de448190b31c7a9af49e5fbd4f5d047.webp?size=256"},"commentCount":0,"comment":[],"position":6,"upvoteCount":0},{"@type":"Comment","text":"\n
hide me
body:has([type=checkbox]:checked) p { display: none;\n}","dateCreated":"2025-03-03T23:24:43.500Z","dateModified":"2025-03-03T23:34:58.712Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/4d4b0b8f-c63c-4294-8173-819b8e1f1e66","name":"Vladimir Drayling","identifier":"4d4b0b8f-c63c-4294-8173-819b8e1f1e66","image":"https://cdn.discordapp.com/avatars/473539443072958465/210293b79467153e504405cd619c40b6.webp?size=256"},"commentCount":0,"comment":[],"position":7,"upvoteCount":0}],"author":{"@type":"Person","url":"https://help.webstudio.is/members/fb7112a6-4f1f-448d-8c5c-c508456b6547","name":"thelamplighter_","identifier":"fb7112a6-4f1f-448d-8c5c-c508456b6547","image":"https://cdn.discordapp.com/embed/avatars/0.png"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0}}]