Published on

Surprisingly Effective Ways To Build A Card With Sidebar With Tailwind CSS

Tags
Card with sidebar

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 Card with sidebar ui component

Based in fluent design - microsoft

Why use Tailwind CSS to create a Card with sidebar ui component?

  • It can make the building process of Card with sidebar ui component faster and more easily.
  • Enables building complex responsive layouts and components freely.
  • Minimum lines of CSS code in Card with sidebar component file.

The preview of Card with sidebar ui component

Free download of the Card with sidebar's source code

The source code of Card with sidebar ui component

<!-- Delete this div -->
<div style="background-color:#333; position:absolute; width: 100%; height: 100%; z-index: -1;"></div>

<style>
  .bg-sidebar {
  	background-color: rgba(255, 255, 255, 0.6);
  }
  
  .btn-sidebar:hover {
    background-color: rgba(255, 255, 255, 0.25);
  }
  
  .bg-content {
    background-color: rgba(255, 255, 255, 0.85);
  }
</style>
<div class="flex w-2/4">
        <div class="flex bg-sidebar">
            <ul class="flex list-none h-full flex-col">
                <li class="p-4 btn-sidebar cursor-pointer"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path opacity=".87" fill="none" d="M0 0h24v24H0V0z"/><path d="M17.51 3.87L15.73 2.1 5.84 12l9.9 9.9 1.77-1.77L9.38 12l8.13-8.13z"/></svg></li>
                <li class="p-4 btn-sidebar cursor-pointer"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zM7.07 18.28c.43-.9 3.05-1.78 4.93-1.78s4.51.88 4.93 1.78C15.57 19.36 13.86 20 12 20s-3.57-.64-4.93-1.72zm11.29-1.45c-1.43-1.74-4.9-2.33-6.36-2.33s-4.93.59-6.36 2.33C4.62 15.49 4 13.82 4 12c0-4.41 3.59-8 8-8s8 3.59 8 8c0 1.82-.62 3.49-1.64 4.83zM12 6c-1.94 0-3.5 1.56-3.5 3.5S10.06 13 12 13s3.5-1.56 3.5-3.5S13.94 6 12 6zm0 5c-.83 0-1.5-.67-1.5-1.5S11.17 8 12 8s1.5.67 1.5 1.5S12.83 11 12 11z"/></svg></li>
                <li class="p-4 btn-sidebar cursor-pointer"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H5.17l-.59.59-.58.58V4h16v12zM6 12h2v2H6zm0-3h2v2H6zm0-3h2v2H6zm4 6h5v2h-5zm0-3h8v2h-8zm0-3h8v2h-8z"/></svg></li>
            </ul>
        </div>
        <div class="w-full flex flex-col bg-content">
            <div class="flex p-5 pb-2">
                <img class="w-1/5 h-full inline-block" src="https://randomuser.me/api/portraits/women/17.jpg">
                <div class="w-4/4 ml-2 inline-block">
                    <div class="text-black text-xl">Lorem ipsum dolor sit amet.</div>
                    <div class="text-gray-800 text-sm">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsam, natus odio. Nobis ratione tempore impedit itaque, nisi, nihil quod dolorem facere error dicta quia at quo numquam incidunt soluta eum!</div>
                </div>
            </div>
            <div class="flex p-5 pb-2">
                <img class="w-1/5 h-full inline-block" src="https://randomuser.me/api/portraits/women/17.jpg">
                <div class="w-4/4 ml-2 inline-block">
                    <div class="text-black text-xl">Lorem ipsum dolor sit amet.</div>
                    <div class="text-gray-800 text-sm">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsam, natus odio. Nobis ratione tempore impedit itaque, nisi, nihil quod dolorem facere error dicta quia at quo numquam incidunt soluta eum!</div>
                </div>
            </div>
            <div class="flex p-5 pb-2 mb-3">
                <img class="w-1/5 h-full inline-block" src="https://randomuser.me/api/portraits/women/17.jpg">
                <div class="w-4/4 ml-2 inline-block">
                    <div class="text-black text-xl">Lorem ipsum dolor sit amet.</div>
                    <div class="text-gray-800 text-sm">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsam, natus odio. Nobis ratione tempore impedit itaque, nisi, nihil quod dolorem facere error dicta quia at quo numquam incidunt soluta eum!</div>
                </div>
            </div>
        </div>
    </div>

How to create a Card with sidebar with Tailwind CSS?

Install tailwind css of verion 1.0.4

Use the link html tag to import the stylesheet of Tailwind CSS of the version 1.0.4

<link href=https://unpkg.com/[email protected]/dist/tailwind.min.css rel="stylesheet">

All the unility class needed to create a Card with sidebar component

  • flex
  • w-2/4
  • bg-sidebar
  • h-full
  • flex-col
  • p-4
  • w-full
  • bg-content
  • p-5
  • pb-2
  • w-1/5
  • inline-block
  • w-4/4
  • ml-2
  • text-black
  • text-xl
  • text-gray-800
  • text-sm
  • mb-3

19 steps to create a Card with sidebar component with Tailwind CSS

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

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

  3. Control the background color of an element to sidebar using the bg-sidebar utilities.

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

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

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

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

  8. Control the background color of an element to content using the bg-content utilities.

  9. Control the padding on all sides of an element to 1.25rem using the p-5 utilities.

  10. Control the padding on bottom side of an element to 0.5rem using the pb-2 utilities.

  11. Use w-1/5 to set an element to a fixed width(1/5).

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

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

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

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

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

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

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

  19. Control the margin on bottom side of an element to 0.75rem using the mb-3 utilities.

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to create a Card with sidebar components, learn and follow along to implement your own components.