- Published on
Practical Guide: Create A Pan-Zoom Control With Tailwind CSS

- What is Tailwind CSS?
- The description of Pan-Zoom Control ui component
- Why use Tailwind CSS to build a Pan-Zoom Control ui component?
- The preview of Pan-Zoom Control ui component
- The source code of Pan-Zoom Control ui component
- How to build a Pan-Zoom Control with Tailwind CSS?
- Install tailwind css of verion 2.2.19
- All the unility class needed to build a Pan-Zoom Control component
- 35 steps to build a Pan-Zoom Control 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 Pan-Zoom Control ui component
Custom pan-zoom canvas control template
Why use Tailwind CSS to build a Pan-Zoom Control ui component?
- It can make the building process of Pan-Zoom Control ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Pan-Zoom Control component file.
The preview of Pan-Zoom Control ui component
Free download of the Pan-Zoom Control's source code
The source code of Pan-Zoom Control ui component
<!-- MDI Icons -->
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/6.5.95/css/materialdesignicons.min.css">
<h1 class="text-center text-3xl font-bold my-20">
< Canvas Container >
</h1>
<div class="flex">
<span class="text-center font-bold my-20 mx-auto">
Pan-zoom icons required MDI (npm i @mdi/font)
<hr class="my-4">
<a href="https://egoistdeveloper.github.io/twcss-to-sass-playground/" target="_blank" class="text-blue-600">
Convetert to SASS
</a>
</span>
</div>
<!-- Panzoom Area -->
<div class="flex fixed right-2 bottom-2 cursor-default">
<!-- Minimap -->
<div class="ngn-minimap">
<div class="flex-initial relative
bg-white bg-opacity-80
rounded shadow
p-2 py-5 mr-2">
<div class="h-full w-full">
<div class="bg-gray-50 border border-gray-200
py-24 px-5">
Add some minimap
</div>
</div>
</div>
</div>
<!-- Pan Controls -->
<div class="flex-initial bg-white bg-opacity-90
rounded shadow p-2 py-2
cursor-default flex flex-col
hover:bg-opacity-100
lg:bottom-3 lg:right-3
transition duration-200 ease-in-out">
<!-- Pan Only -->
<button class="w-9 h-9 min-w-min
rounded-full text-lg mb-2
bg-gray-300 bg-opacity-30
border border-gray-300 border-opacity-30
hover:bg-yellow-400 hover:bg-opacity-50
outline-none hover:shadow-md
transition duration-200 ease-in-out"
title="Pan-only Mode">
<i class="mdi mdi-focus-field"></i>
</button>
<!-- Pan Reset -->
<button class="w-9 h-9 min-w-min
rounded-full text-lg mb-2
bg-gray-300 bg-opacity-30
border border-gray-300 border-opacity-30
hover:bg-yellow-400 hover:bg-opacity-50
outline-none hover:shadow-md
transition duration-200 ease-in-out"
title="Reset Pan View">
<i class="mdi mdi-image-filter-center-focus"></i>
</button>
<!-- Zoom Controls-->
<div class="flex flex-col">
<button class="w-9 h-9 min-w-min
rounded-none rounded-t-full text-lg
bg-gray-300 bg-opacity-30
border border-gray-300 border-opacity-30
hover:bg-yellow-400 hover:bg-opacity-50
outline-none hover:shadow-md
transition duration-200 ease-in-out
mb-0 border
border-gray-300 border-opacity-30
hover:border-yellow-200"
title="Zoom In">
<i class="mdi mdi-minus"></i>
</button>
<div class="bg-gray-300 bg-opacity-30
border border-b border-gray-300 border-opacity-30
font-medium py-2 cursor-default
w-9 h-9 min-w-min
text-xs text-center
inline-block align-baseline">
123%
</div>
<button class="w-9 h-9 min-w-min
rounded-none rounded-b-full text-lg
bg-gray-300 bg-opacity-30
border border-gray-300 border-opacity-30
hover:bg-yellow-400 hover:bg-opacity-50
outline-none hover:shadow-md
transition duration-200 ease-in-out
mb-0 border
border-gray-300 border-opacity-30
hover:border-yellow-200"
title="Zoom Out">
<i class="mdi mdi-plus"></i>
</button>
</div>
<!-- Show Minimap -->
<button class="w-9 h-9 min-w-min
rounded-full text-lg mt-2
bg-gray-300 bg-opacity-30
border border-gray-300 border-opacity-30
hover:bg-yellow-400 hover:bg-opacity-50
outline-none hover:shadow-md
transition duration-200 ease-in-out"
title="Show Mini Map">
<i class="mdi mdi-map-outline"></i>
</button>
</div>
</div>
How to build a Pan-Zoom Control with Tailwind CSS?
Install tailwind css of verion 2.2.19
Use the script
html tag to import the script of Tailwind CSS of the version 2.2.19
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to build a Pan-Zoom Control component
text-center
text-3xl
my-20
flex
mx-auto
my-4
text-blue-600
fixed
right-2
bottom-2
flex-initial
bg-white
p-2
py-5
mr-2
h-full
w-full
bg-gray-50
border-gray-200
py-24
px-5
lg:bottom-3
w-9
h-9
text-lg
bg-gray-300
border-gray-300
hover:bg-yellow-400
flex-col
mb-0
hover:border-yellow-200
border-b
py-2
text-xs
inline-block
35 steps to build a Pan-Zoom Control component with Tailwind CSS
Control the text color of an element to center using the
text-center
utilities.Control the text color of an element to 3xl using the
text-3xl
utilities.Control the vertical margin of an element to 5rem using the
my-20
utilities.Use
flex
to create a block-level flex container.Control the horizontal margin of an element to auto using the
mx-auto
utilities.Control the vertical margin of an element to 1rem using the
my-4
utilities.Control the text color of an element to blue-600 using the
text-blue-600
utilities.Use
fixed
to position an element relative to the browser window.Use the
right-2
utilities to set the right position of a positioned element to 0.5rem.Use the
bottom-2
utilities to set the bottom position of a positioned element to 0.5rem.Use
flex
to create a block-level flex container.Control the background color of an element to white using the
bg-white
utilities.Control the padding on all sides of an element to 0.5rem using the
p-2
utilities.Control the vertical padding of an element to 1.25rem using the
py-5
utilities.Control the margin on right side of an element to 0.5rem using the
mr-2
utilities.Use
h-full
to set an element’s height to 100% of its parent, as long as the parent has a defined height.Use
w-full
to set an element to a 100% based width.Control the background color of an element to gray-50 using the
bg-gray-50
utilities.Control the border color of an element to gray-200 using the
border-gray-200
utilities.Control the vertical padding of an element to 6rem using the
py-24
utilities.Control the horizontal padding of an element to 1.25rem using the
px-5
utilities.Use the
lg:bottom-3
utilities to set the bottom position of a positioned element to 0.75rem at only large screen sizes.Use
w-9
to set an element to a fixed width(2.25rem).Use
h-9
to set an element to a fixed height(2.25rem).Control the text color of an element to lg using the
text-lg
utilities.Control the background color of an element to gray-300 using the
bg-gray-300
utilities.Control the border color of an element to gray-300 using the
border-gray-300
utilities.Control the background color of an element to yellow-400 using the
hover:bg-yellow-400
utilities on hover.Use
flex
to create a block-level flex container.Control the margin on bottom side of an element to 0rem using the
mb-0
utilities.Control the border color of an element to yellow-200 using the
hover:border-yellow-200
utilities on hover.Control the border color of an element to b using the
border-b
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the text color of an element to xs using the
text-xs
utilities.Use
inline-block
utilities to wrap the element to prevent the text inside from extending beyond its parent.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to build a Pan-Zoom Control components, learn and follow along to implement your own components.