Show More and Show Less Button

This tutorial explains how to create a Show More and Show Less button in Joomla without advanced technical skills...

Tools

Code editor

Estimated time

5 min.

Adding Class Suffix to a Collapse Item

1. Add the class suffix read-more-content read-more-hidden to any section, row, or nested row that should be collapsed.

Adding Class Suffix to a Button

2. Add a class suffix read-more-button to the button that will open/close the collapsed element.

 

*Important! The button must be placed outside the collapsed section, row, or nested row.

Adding CSS

3. Copy CSS code below, go to Tools ➝ Code Editor ➝ CSS and paste it.

 

.page .read-more-content {
    box-sizing: content-box;
    overflow: hidden;
    transition: height 0.5s ease;
}
.page .read-more-hidden {
    height: 100px !important;
    mask-image: linear-gradient(to bottom, black 40%, transparent 100%);
}

100px visible height when collapsed. Change this value to adjust.

Adding JavaScript

4. Copy JavaScript code below, go to Tools ➝ Code Editor ➝ JavaScript and paste it.

 


window.addEventListener("load", () => {
    const row = document.querySelector('.read-more-content');
    const btn = document.querySelector('.read-more-button a span');
    if (!row || !btn) return;
    const column = [...row.children].find(el => !el.classList.contains('ba-overlay'));
    const setHeight = () => row.style.height = (column?.scrollHeight || 0) + 'px';
    btn.textContent = "Show more";
    setHeight();
    document.addEventListener('click', e => {
        if (!e.target.closest('.read-more-button a')) return;
        e.preventDefault();
        const hidden = row.classList.toggle('read-more-hidden');
        btn.textContent = hidden ? "Show more" : "Show less";
        setHeight();
    });
});

Replace "Show more" and "Show less" with your own button labels.

Something is not clear? Ask a question on community forums.