<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Damianos Giankakis on Medium]]></title>
        <description><![CDATA[Stories by Damianos Giankakis on Medium]]></description>
        <link>https://medium.com/@damianosg?source=rss-2cb71d76cc90------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JwPfKNkBzOnR3GrLAypvXg.jpeg</url>
            <title>Stories by Damianos Giankakis on Medium</title>
            <link>https://medium.com/@damianosg?source=rss-2cb71d76cc90------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:36:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@damianosg/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A pure Bootstrap Carousel & Horizontal Accordion]]></title>
            <link>https://medium.com/@damianosg/a-pure-bootstrap-carousel-horizontal-accordion-7714907fbe1c?source=rss-2cb71d76cc90------2</link>
            <guid isPermaLink="false">https://medium.com/p/7714907fbe1c</guid>
            <category><![CDATA[accordion]]></category>
            <category><![CDATA[carousel]]></category>
            <category><![CDATA[horizontal]]></category>
            <category><![CDATA[bootstrap-5]]></category>
            <dc:creator><![CDATA[Damianos Giankakis]]></dc:creator>
            <pubDate>Tue, 17 Oct 2023 17:01:35 GMT</pubDate>
            <atom:updated>2023-10-17T17:01:35.389Z</atom:updated>
            <content:encoded><![CDATA[<p>Every wondered how to achieve a horiontzal accordion, and a carousel at the same time, without re-inventing the wheel?</p><p>Well, the solution for the first is already out there thanks to <a href="https://mdbootstrap.com/docs/standard/extended/horizontal-accordion/">MDBootstrap</a>. But to give you a solution to the second problem I decided to write this small article / tutorial. All the code is available on my <a href="https://github.com/Damian96/pure-bs-carousel-accordion">GitHub repository</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NIzwfnz_TTaARZTtp_yQMQ.png" /></figure><p>First lets install all the required dependencies:</p><pre>$ npm i bootstrap@5.3.2 jquery@3.7.1</pre><p>Next step is to create a container for our <a href="https://getbootstrap.com/docs/5.0/components/carousel/#with-indicators">Carousel with indicators</a>:</p><pre>&lt;div id=&quot;pureBsAccordionCarousel&quot; class=&quot;carousel carousel-dark slide&quot; data-bs-ride=&quot;carousel&quot;&gt;<br><br>    &lt;div class=&quot;carousel-indicators mb-0&quot;&gt;<br>        &lt;button type=&quot;button&quot; data-bs-target=&quot;#pureBsAccordionCarousel&quot; data-bs-slide-to=&quot;0&quot; class=&quot;active&quot; aria-current=&quot;true&quot; aria-label=&quot;Slide 1&quot;&gt;&lt;/button&gt;<br>        &lt;button type=&quot;button&quot; data-bs-target=&quot;#pureBsAccordionCarousel&quot; data-bs-slide-to=&quot;1&quot; aria-label=&quot;Slide 2&quot;&gt;&lt;/button&gt;<br>        &lt;button type=&quot;button&quot; data-bs-target=&quot;#pureBsAccordionCarousel&quot; data-bs-slide-to=&quot;2&quot; aria-label=&quot;Slide 3&quot;&gt;&lt;/button&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;carousel-inner&quot;&gt;<br>      ...<br>    &lt;/div&gt;<br>    &lt;button class=&quot;carousel-control-prev carousel-control&quot; type=&quot;button&quot; data-bs-target=&quot;#pureBsAccordionCarousel&quot; data-bs-slide=&quot;prev&quot;&gt;<br>        &lt;span class=&quot;carousel-control-prev-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;<br>        &lt;span class=&quot;visually-hidden&quot;&gt;Previous&lt;/span&gt;<br>    &lt;/button&gt;<br>    &lt;button class=&quot;carousel-control-next carousel-control&quot; type=&quot;button&quot; data-bs-target=&quot;#pureBsAccordionCarousel&quot; data-bs-slide=&quot;next&quot;&gt;<br>        &lt;span class=&quot;carousel-control-next-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;<br>        &lt;span class=&quot;visually-hidden&quot;&gt;Next&lt;/span&gt;<br>    &lt;/button&gt;<br>&lt;/div&gt;</pre><p>Third step is to add some items to our carousel. In my version each item has 3 ‘Cards’ and the first is by default expanded. You can modify the widths of the cards if you desire to add more items in every slide.</p><pre>&lt;!-- Carousel Inner --&gt;<br>&lt;div class=&quot;carousel-item&quot;&gt;<br>    &lt;div class=&quot;card bg-primary expand text-white mx-2&quot;&gt;<br>        &lt;div class=&quot;card-body&quot;&gt;<br>            &lt;h5 class=&quot;card-title&quot;&gt;Card 1&lt;/h5&gt;<br>            &lt;p class=&quot;card-text&quot;&gt;Some quick example text to build on the card title and make up the bulk of the card&#39;s content.&lt;/p&gt;<br>            &lt;button type=&quot;button&quot; class=&quot;btn btn-outline-light&quot; data-mdb-ripple-color=&quot;dark&quot;&gt;Button&lt;/button&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br><br>    &lt;div class=&quot;card small bg-danger text-dark mx-2&quot;&gt;<br>        &lt;div class=&quot;card-body&quot;&gt;<br>            &lt;h5 class=&quot;card-title&quot;&gt;Card 3&lt;/h5&gt;<br>            &lt;p class=&quot;card-text&quot;&gt;Some quick example text to build on the card title and make up the bulk of the card&#39;s content.&lt;/p&gt;<br>            &lt;button type=&quot;button&quot; class=&quot;btn btn-outline-light&quot; data-mdb-ripple-color=&quot;dark&quot;&gt;Button&lt;/button&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br><br>    &lt;div class=&quot;card small bg-secondary text-dark mx-2&quot;&gt;<br>        &lt;div class=&quot;card-body&quot;&gt;<br>            &lt;h5 class=&quot;card-title&quot;&gt;Card 2&lt;/h5&gt;<br>            &lt;p class=&quot;card-text&quot;&gt;Some quick example text to build on the card title and make up the bulk of the card&#39;s content.&lt;/p&gt;<br>            &lt;button type=&quot;button&quot; class=&quot;btn btn-outline-dark&quot; data-mdb-ripple-color=&quot;dark&quot;&gt;Button&lt;/button&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;/div&gt;<br>&lt;div class=&quot;carousel-item&quot;&gt;<br>    &lt;div class=&quot;card bg-warning expand text-dark mx-2&quot;&gt;<br>        &lt;div class=&quot;card-body&quot;&gt;<br>            &lt;h5 class=&quot;card-title&quot;&gt;Card 1&lt;/h5&gt;<br>            &lt;p class=&quot;card-text&quot;&gt;Some quick example text to build on the card title and make up the bulk of the card&#39;s content.&lt;/p&gt;<br>            &lt;button type=&quot;button&quot; class=&quot;btn btn-outline-light&quot; data-mdb-ripple-color=&quot;dark&quot;&gt;Button&lt;/button&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br><br>    &lt;div class=&quot;card small bg-secondary text-dark mx-2&quot;&gt;<br>        &lt;div class=&quot;card-body&quot;&gt;<br>            &lt;h5 class=&quot;card-title&quot;&gt;Card 2&lt;/h5&gt;<br>            &lt;p class=&quot;card-text&quot;&gt;Some quick example text to build on the card title and make up the bulk of the card&#39;s content.&lt;/p&gt;<br>            &lt;button type=&quot;button&quot; class=&quot;btn btn-outline-dark&quot; data-mdb-ripple-color=&quot;dark&quot;&gt;Button&lt;/button&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br><br>    &lt;div class=&quot;card small bg-info text-white mx-2&quot;&gt;<br>        &lt;div class=&quot;card-body&quot;&gt;<br>            &lt;h5 class=&quot;card-title&quot;&gt;Card 3&lt;/h5&gt;<br>            &lt;p class=&quot;card-text&quot;&gt;Some quick example text to build on the card title and make up the bulk of the card&#39;s content.&lt;/p&gt;<br>            &lt;button type=&quot;button&quot; class=&quot;btn btn-outline-light&quot; data-mdb-ripple-color=&quot;dark&quot;&gt;Button&lt;/button&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;/div&gt;<br>&lt;!-- /Carousel Inner --&gt;</pre><p>Then we add the CSS that is required to make the cards expand and shrink as we want.</p><pre>.card {<br>  display: inline-block;<br>  height: 180px;<br>  padding: 0;<br>  overflow: hidden;<br>  align-items: center;<br>  transition: width 0.2s;<br>  border-radius: 3px;<br><br>  &amp;.expand {<br>    width: 65%;<br>  }<br>  &amp;.unset {<br>    width: 16%;<br>    color: black !important;<br>    background-color: #ddd !important;<br>  }<br>  &amp;.small {<br>    width: 5%;<br>    background-color: #ddd !important;<br><br>    &amp; &gt; div {<br>      opacity: 0;<br>    }<br>  }<br>  &amp;.unset &gt; div &gt; p {<br>    opacity: 0;<br>  }<br><br>  &amp;.expand &gt; div {<br>    transition-delay: 200ms;<br>    opacity: 1;<br>  }<br>}</pre><p>Also add some styling to the Carousel to place the indicators and controls in their correct position.</p><pre>.carousel {<br>  display: flex;<br>  justify-content: center;<br>  align-items: center;<br><br>  &amp;-indicators {<br>    transform: translateY(100%);<br>  }<br>  &amp;-control {<br>    &amp;-prev {<br>      transform: translateX(-100%);<br>    }<br>    &amp;-next {<br>      transform: translateX(100%);<br>    }<br>  }<br>}</pre><p>In this stage, the carousel is not functioning correctly at all. The trick is to add Event Listeners on the Bootstrap Carousel’s events <em>slide.bs.carousel</em>, <em>slid.bs.carousel</em>, so whenever a new slide is requested by the user, we expand the first card, and we shrink all the other inactive cards.</p><pre>$(function () {<br>  const $cards = $(&quot;.carousel-item .card&quot;);<br>  $cards.each(function (index, element) {<br>    element.addEventListener(&quot;click&quot;, () =&gt; {<br>      $cards.removeClass(&quot;expand&quot;).removeClass(&quot;unset&quot;).addClass(&quot;small&quot;);<br>      element.classList.remove(&quot;small&quot;);<br>      $(element).addClass(&quot;expand active&quot;);<br>    });<br>  });<br><br>  const carousel = document.getElementById(&quot;pureBsAccordionCarousel&quot;);<br>  new bootstrap.Carousel(carousel);<br><br>  carousel.addEventListener(&quot;slide.bs.carousel&quot;, function (event) {<br>    $cards.removeClass(&quot;active&quot;);<br>    const $activeItem = $(event.relatedTarget);<br>    $activeItem<br>      .find(&quot;.card&quot;)<br>      .first()<br>      .removeClass(&quot;small&quot;)<br>      .addClass(&quot;expand active&quot;);<br>  });<br><br>  carousel.addEventListener(&quot;slid.bs.carousel&quot;, function () {<br>    $cards<br>      .filter(&quot;.expand&quot;)<br>      .not(&quot;.active&quot;)<br>      .removeClass(&quot;expand&quot;)<br>      .addClass(&quot;small&quot;);<br>  });<br>});</pre><p>In combination with the JavaScript code of MDBootstrap, we have the desired result.</p><p>Congratulations!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7714907fbe1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>