Published on

Learn How To Create A Fully Interactive Frames Slider With Tailwind CSS from the Pros

Fully Interactive Frames Slider

What is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.

The description of Fully Interactive Frames Slider ui component

This can be used with ajax or with html only

Why use Tailwind CSS to make a Fully Interactive Frames Slider ui component?

  • It can make the building process of Fully Interactive Frames Slider ui component faster and more easily.
  • Enables building complex responsive layouts and components freely.
  • Minimum lines of CSS code in Fully Interactive Frames Slider component file.

The preview of Fully Interactive Frames Slider ui component

Free download of the Fully Interactive Frames Slider's source code

The source code of Fully Interactive Frames Slider ui component

<div class="text-xl font-bold m-5 text-center">Use Keyboard Arrow Keys To Go Left And Right</div>

    <div class="gallery border-2 rounded mx-auto m-5 bg-white" style="width:750px;">
        <div class="top flex p-2 border-b select-none">
          <div class="heading text-gray-800 w-full pl-3 font-semibold my-auto"></div>
          <div class="buttons ml-auto flex text-gray-600 mr-1">
            <svg action="prev" class="w-7 border-2 rounded-l-lg p-1 cursor-pointer border-r-0" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path action="prev" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18" /></svg>
            <svg action="next" class="w-7 border-2 rounded-r-lg p-1 cursor-pointer" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path action="next" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 5l7 7m0 0l-7 7m7-7H3" /></svg>
          </div>
        </div>
        <div class="content-area w-full h-96 overflow-hidden">
          <div class="platform shadow-xl h-full flex">
            <!-- frame start -->
            <div class="each-frame border-box flex-none h-full" title="Tiger"> <!-- title shows in top -->
                <!-- this is full editable area -->
                <div class="main flex w-full p-8"> 
                    <div class="sub w-4/6 my-auto">
                        <img class="w-full p-8" src="https://images-na.ssl-images-amazon.com/images/I/81eJpEEQwYL._AC_SL1500_.jpg" alt="">
                    </div>
                    <div class="sub w-full my-auto">
                        <div class="head text-3xl font-bold mb-4">The Tiger</div>
                        <div class="long-text text-lg">(Panthera tigris) is the largest extant cat species and a member of the genus Panthera. It is most recognisable for its dark vertical stripes on orange-brown fur with a lighter underside. It is an apex predator, primarily preying on ungulates such as deer and wild boar.</div> 
                        <!-- this buttons are usable everywhere inside gallery element -->
                        <div class="goto border border-gray-400 text-sm font-semibold inline-block mt-2 p-1 px-2 rounded cursor-pointer" action="goto" goto="2">Goto Third Frame</div><!-- add (action="goto" goto="[val]{0 means first frame and so on}") attribute to jump into frames -->
                        <div class="goto border border-gray-400 text-sm font-semibold inline-block mt-2 p-1 px-2 rounded cursor-pointer" action="goto" goto="end">Goto Last Frame</div> 
                    </div>
                </div>
            </div>
            <!-- frame end -->

            <div class="each-frame border-box flex-none h-full" title="Lion"> <!-- title shows in top -->
                <!-- this is full editable area -->
                <div class="main flex w-full p-8"> 
                    <div class="sub w-4/6 my-auto">
                        <img class="w-full p-8" src="https://image.freepik.com/free-vector/cute-lion-cartoon_160606-353.jpg" alt="">
                    </div>
                    <div class="sub w-full my-auto">
                        <div class="head text-3xl font-bold mb-4">The Lion</div>
                        <div class="long-text text-lg">The lion is a species in the family Felidae and a member of the genus Panthera. It has a muscular, deep-chested body, short, rounded head, round ears, and a hairy tuft at the end of its tail. It is sexually dimorphic; adult male lions have a prominent mane.</div> 
                    </div>
                </div>
            </div>
            <!-- frame end -->

            <div class="each-frame border-box flex-none h-full" title="Rat"> <!-- title shows in top -->
                <!-- this is full editable area -->
                <div class="main flex w-full p-8"> 
                    <div class="sub w-4/6 my-auto">
                        <img class="w-full p-8" src="https://i.pinimg.com/originals/07/1d/d0/071dd09d7b36e49139fe2cf08ff728a8.jpg" alt="">
                    </div>
                    <div class="sub w-full my-auto">
                        <div class="head text-3xl font-bold mb-4">The Rat</div>
                        <div class="long-text text-lg">Rats are various medium-sized, long-tailed rodents. Species of rats are found throughout the order Rodentia, but stereotypical rats are found in the genus Rattus. Other rat genera include Neotoma, Bandicota and Dipodomys. Rats are typically distinguished from</div> 
                    </div>
                </div>
            </div>
            <!-- frame end -->

            <div class="each-frame border-box flex-none h-full" title="Owl"> <!-- title shows in top -->
                <!-- this is full editable area -->
                <div class="main flex w-full p-8"> 
                    <div class="sub w-4/6 my-auto">
                        <img class="w-full p-8" src="https://image.freepik.com/free-vector/cartoon-owl-tree-branch_194935-43.jpg" alt="">
                    </div>
                    <div class="sub w-full my-auto">
                        <div class="head text-3xl font-bold mb-4">The Owl</div>
                        <div class="long-text text-lg">Owls are birds from the order Strigiformes, which includes over 200 species of mostly solitary and nocturnal birds of prey typified by an upright stance, a large, broad head, binocular vision, binaural hearing, sharp talons, and feathers adapted for silent flight.</div> 
                        <div class="goto border border-gray-400 text-sm font-semibold inline-block mt-2 p-1 px-2 rounded cursor-pointer" action="goto" goto="0">Goto First Frame</div>
                    </div>
                </div>
            </div>
            <!-- frame end -->


          </div>
        </div>
      </div>

      <style>
          .platform{
              position: relative;
              transition:right 0.3s;
          }
          .body{background-color:white !important;}
      </style>

      <script>
          function gallery(){
              this.index=0;
              this.load=function(){
                this.rootEl = document.querySelector(".gallery");
                this.platform = this.rootEl.querySelector(".platform");
                this.frames = this.platform.querySelectorAll(".each-frame");
                this.contentArea = this.rootEl.querySelector(".content-area");      
                this.width = parseInt(this.rootEl.style.width);
                this.limit = {start:0,end:this.frames.length-1};
                this.frames.forEach(each=>{each.style.width=this.width+"px";});   
                this.goto(this.index);      
              }
              this.set_title = function(){this.rootEl.querySelector(".heading").innerText=this.frames[this.index].getAttribute("title");}
              this.next = function(){this.platform.style.right=this.width * ++this.index + "px";this.set_title();}
              this.prev = function(){this.platform.style.right=this.width * --this.index + "px";this.set_title();}
              this.goto = function(index){this.platform.style.right = this.width * index + "px";this.index=index;this.set_title();}
              this.load();
          }
          var G = new gallery();
            G.rootEl.addEventListener("click",function(t){
                var val = t.target.getAttribute("action");
                if(val == "next" && G.index != G.limit.end){G.next();}
                if(val == "prev" && G.index != G.limit.start){G.prev();}
                if(val == "goto"){
                    let rv = t.target.getAttribute("goto");
                    rv = rv == "end" ? G.limit.end:rv;
                    G.goto(parseInt(rv));
                }
            });
            document.addEventListener("keyup",function(t){
                var val = t.keyCode;
                if(val == 39 && G.index != G.limit.end){G.next();}
                if(val == 37 && G.index != G.limit.start){G.prev();}
            });

            // run G.load() if new data loaded with ajax

      </script>

How to make a Fully Interactive Frames Slider with Tailwind CSS?

Install tailwind css of verion 2.0.3

Use the script html tag to import the script of Tailwind CSS of the version 2.0.3

<script src="https://cdn.tailwindcss.com"></script>

All the unility class needed to make a Fully Interactive Frames Slider component

  • text-xl
  • m-5
  • text-center
  • border-2
  • mx-auto
  • bg-white
  • flex
  • p-2
  • border-b
  • text-gray-800
  • w-full
  • pl-3
  • my-auto
  • ml-auto
  • text-gray-600
  • mr-1
  • w-7
  • p-1
  • border-r-0
  • h-96
  • overflow-hidden
  • h-full
  • border-box
  • flex-none
  • p-8
  • w-4/6
  • text-3xl
  • mb-4
  • text-lg
  • border-gray-400
  • text-sm
  • inline-block
  • mt-2
  • px-2

34 steps to make a Fully Interactive Frames Slider component with Tailwind CSS

  1. Control the text color of an element to xl using the text-xl utilities.

  2. Control the margin on all sides of an element to 1.25rem using the m-5 utilities.

  3. Control the text color of an element to center using the text-center utilities.

  4. Control the border color of an element to 0.5rem using the border-2 utilities.

  5. Control the horizontal margin of an element to auto using the mx-auto utilities.

  6. Control the background color of an element to white using the bg-white utilities.

  7. Use flex to create a block-level flex container.

  8. Control the padding on all sides of an element to 0.5rem using the p-2 utilities.

  9. Control the border color of an element to b using the border-b utilities.

  10. Control the text color of an element to gray-800 using the text-gray-800 utilities.

  11. Use w-full to set an element to a 100% based width.

  12. Adjust the left padding of the element to 0.75rem using the pl-3 utilities class

  13. Control the vertical margin of an element to auto using the my-auto utilities.

  14. Control the margin on left side of an element to auto using the ml-auto utilities.

  15. Control the text color of an element to gray-600 using the text-gray-600 utilities.

  16. Control the margin on right side of an element to 0.25rem using the mr-1 utilities.

  17. Use w-7 to set an element to a fixed width(1.75rem).

  18. Control the padding on all sides of an element to 0.25rem using the p-1 utilities.

  19. Control the border color of an element to r-0 using the border-r-0 utilities.

  20. Use h-96 to set an element to a fixed height(24rem).

  21. Use overflow-hidden to clip any content within an element that overflows the bounds of that element.

  22. Use h-full to set an element’s height to 100% of its parent, as long as the parent has a defined height.

  23. Control the border color of an element to box using the border-box utilities.

  24. Use flex to create a block-level flex container.

  25. Control the padding on all sides of an element to 2rem using the p-8 utilities.

  26. Use w-4/6 to set an element to a fixed width(4/6).

  27. Control the text color of an element to 3xl using the text-3xl utilities.

  28. Control the margin on bottom side of an element to 1rem using the mb-4 utilities.

  29. Control the text color of an element to lg using the text-lg utilities.

  30. Control the border color of an element to gray-400 using the border-gray-400 utilities.

  31. Control the text color of an element to sm using the text-sm utilities.

  32. Use inline-block utilities to wrap the element to prevent the text inside from extending beyond its parent.

  33. Control the margin on top side of an element to 0.5rem using the mt-2 utilities.

  34. Control the horizontal padding of an element to 0.5rem using the px-2 utilities.

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to make a Fully Interactive Frames Slider components, learn and follow along to implement your own components.