I want to replace a script I have that allows users to "read more" with the Bootstrap collapse accordion. My problem is that as far as I've seen the accordion is either open or closed.
Does anyone know about an option to show some text in closed mode?
In the script I'm using right now I can make some text visible by changing the height of the text area, but in Bootstrap this option doesn't work. When I change the height of .in
or .out
(the css that controls the text area height), it simply opens and closes until that height. Has anybody found a workaround for this?
My HTML:
<div class="accordion" id="accordion2">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" href="#collapseOne"
data-toggle="collapse" data-parent="#accordion2">
TITLE OF THE COLLAPSE
</a>
</div>
<div id="collapseOne" class="accordion-body collapse in">
<div class="accordion-inner">
DATA IN THE COLLAPSE
</div>
</div>
</div>
</div>
Here's another approach if you can't breakup your DOM into different pieces for the preview + expanded text, but have one long block of content.
Bootstrap uses the selector
.collapse:not(.show)
to hide the accordion-body. We can override those styles to be visible, but only up to a certain height. Then, to indicate there's additional text, we can borrow some styling from How to apply a CSS gradient over a text, from a transparent to an opaque colour.Add the
accordion-preview
class to the top level component and add the following styles:Example
Demo in Stack Snippets