- Published on
Imagine You Make A Simple Modal With Tailwind CSS Like An Expert. Follow These 6 Steps To Get There

- What is Tailwind CSS?
- The description of Simple Modal ui component
- Why use Tailwind CSS to make a Simple Modal ui component?
- The preview of Simple Modal ui component
- The source code of Simple Modal ui component
- How to make a Simple Modal with Tailwind CSS?
- Install tailwind css of verion 0.3.0
- All the unility class needed to make a Simple Modal component
- 22 steps to make a Simple Modal component with Tailwind CSS
- Conclusion
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 Simple Modal ui component
A simple modal that you can drop into any project
Why use Tailwind CSS to make a Simple Modal ui component?
- It can make the building process of Simple Modal ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Simple Modal component file.
The preview of Simple Modal ui component
Free download of the Simple Modal's source code
The source code of Simple Modal ui component
<div class="h-screen w-full flex flex-col items-center justify-center bg-teal-lightest font-sans">
<div v-if="modal.visible" @click.self="modal.visible = false" class="h-screen w-full absolute flex items-center justify-center bg-modal">
<div class="bg-white rounded shadow p-8 m-4 max-w-xs max-h-full text-center overflow-y-scroll">
<div class="mb-4">
<h1>Welcome!</h1>
</div>
<div class="mb-8">
<p>Ready to get started? Keep scrolling to see some great components.</p>
</div>
<div class="flex justify-center">
<button class="flex-no-shrink text-white py-2 px-4 rounded bg-teal hover:bg-teal-dark">Let's Go</button>
</div>
</div>
</div>
</div>
How to make a Simple Modal with Tailwind CSS?
Install tailwind css of verion 0.3.0
Use the link
html tag to import the stylesheet of Tailwind CSS of the version 0.3.0
<link href=https://unpkg.com/[email protected]/dist/tailwind.min.css rel="stylesheet">
All the unility class needed to make a Simple Modal component
h-screen
w-full
flex
flex-col
bg-teal-lightest
absolute
bg-modal
bg-white
p-8
m-4
max-w-xs
max-h-full
text-center
overflow-y-scroll
mb-4
mb-8
flex-no-shrink
text-white
py-2
px-4
bg-teal
hover:bg-teal-dark
22 steps to make a Simple Modal component with Tailwind CSS
Use
h-screen
to make an element span the entire height of the viewport.Use
w-full
to set an element to a 100% based width.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Control the background color of an element to teal-lightest using the
bg-teal-lightest
utilities.Use
absolute
to position an element outside of the normal flow of the document, causing neighboring elements to act as if the element doesn’t exist.Control the background color of an element to modal using the
bg-modal
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the padding on all sides of an element to 2rem using the
p-8
utilities.Control the margin on all sides of an element to 1rem using the
m-4
utilities.Set the maximum width/height of an element using the
max-w-xs
utilities.Set the maximum width/height of an element using the
max-h-full
utilities.Control the text color of an element to center using the
text-center
utilities.Use
overflow-y-scroll
to allow vertical scrolling and always show scrollbars unless always-visible scrollbars are disabled by the operating system.Control the margin on bottom side of an element to 1rem using the
mb-4
utilities.Control the margin on bottom side of an element to 2rem using the
mb-8
utilities.Use
flex
to create a block-level flex container.Control the text color of an element to white using the
text-white
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the horizontal padding of an element to 1rem using the
px-4
utilities.Control the background color of an element to teal using the
bg-teal
utilities.Control the background color of an element to teal-dark using the
hover:bg-teal-dark
utilities on hover.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to make a Simple Modal components, learn and follow along to implement your own components.