We at times have a rather long footer copyright section. We decided to make the rather lengthy section be smaller and then expand to display more if you wanted to read all of it.
I'm using the Collapse method http://getbootstrap.com/javascript/#collapse rather then some others because I'm using the built-in method and the CSS just swaps the text. I don't have to write additional JS to swap the text or expand function. Also I didn't want to de-construct the styling of the Accordion.
So I start with a sentence then at the end I have a link that has nothing but a "space" for it.
The CSS below is what controls the "text" that is displayed based on the state of the collapsed/expanded being true or false. It will inject into the link the text that is in the content property value. When you first come to the page it displays [View More] when clicked it expands and then displays [View Less] for the link, click again and it collapses the expanded content and once again the link is back to saying [View More].
footer .viewMore[aria-expanded="false"]:before{
content:"[ View More ]";
}
footer .viewMore[aria-expanded="true"]:before{
content:"[ View Less ]";
}
Before Bootstrap, I had used a hidden checkbox to do a similar thing. It doesn't have to be related only to the footer, I've used this method for other areas of my pages.
Thank you for sharing this, Saj! This is a great trick and you are saving yourself from having to write custom JS. I am sure I'll put this to good use some day :)
@alshariff, the code I provided is literally the code. The key is pretty much the CSS code.
footer .viewMore[aria-expanded="false"]:before{
content:"[ View More ]";
}
footer .viewMore[aria-expanded="true"]:before{
content:"[ View Less ]";
}
The Collapse component already has all the expanding/collapsing function built into it from the Bootstrap framework. All I am doing (i.e. the CSS) is swapping what the text says in the button/link that you click to cause the expand/collapse.
So if you wanted to just use the Collapse component in the BSS app, you could. Unfortunately, the Collapse component is locked so you can't add any text before the button in the component it's self but you could right click on the component in the Overview pane and select Convert to HTML to so you can use the Custom Code block to get around it :)
Just drag/drop the Collapse component where ever you want it. Then in the Overview pane select the Collapse component and expand it and then select the Button element. Then expand the HTML pane and then the Attribute pane add the class viewMore. Then select the text of the button and delete it.
<div>
< a class="btn btn-default viewMore" data-toggle="collapse" aria-expanded="false" aria-controls="collapse-1" role="button" href="#collapse-1"><!-- space --></a>
<div class="collapse" id="collapse-1">
<p>Collapse content.</p>
</div>
</div>
Then add your CSS which would be this.
.viewMore[aria-expanded="false"]:before {
content:"[ View More ]";
}
.viewMore[aria-expanded="true"]:before {
content:"[ View Less ]";
}
You should see the text in the button as [ View More ] even in the BSS app, but, to test it you have to use the Preview feature of the app in the top right of the app.
If you were looking for the checkbox trick, this is the code for that. Using all drag/drop components
HTML example
<span>Just some text </span>
<input type="checkbox" class="hidden" id="testlink" />
<label for="testlink"> Link to click on to view <span> </span></label>
<p>Paragraph content</p>
Hi Saj,
I am also new in Bootstrap and I would like your idea but it does not work for me. I tried it in JSFiddle and the link text did not change.
Could you help me, please.