Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind CSS how to code pixel perfect design

Tags:

Just started to use https://tailwindcss.com

And can't figure out how to code pixel perfect design only with tailwind classes. Simple example, I need padding-left 22px but closest tailwind class is pl-6 and pl-8 which is 24px and 32px respectively. So at the end of the day, I have a bunch of tailwind classes + 1 custom where I make arrangements this defeats the purpose of this framework "utilities first".

like image 752
RomkaLTU Avatar asked Feb 10 '19 15:02

RomkaLTU


People also ask

Is Tailwind CSS difficult?

It Takes Time to LearnBecause of the built-in classes, Tailwind CSS is quite learning-intensive. Even for experienced developers, it can be a challenge to learn how to use and fully utilize the pre-built classes. But, of course, as with any other development task, practice makes perfect.

Is Tailwind CSS heavy?

The default Tailwind configuration comes with 36.4KB minified and g-zipped. Compared to Bootstrap at 22.1KB , Tailwind is 14.3KB heavier.

Is Tailwind good for responsive design?

Every utility class in Tailwind can be applied conditionally at different breakpoints, which makes it a piece of cake to build complex responsive interfaces without ever leaving your HTML.

How do I set the height on my px Tailwind?

Use h-{number} or h-px to set an element to a fixed height.


1 Answers

Ok got it, I need to edit tailwind.config.js and set custom sizes there. For example:

height: [   ...   '278px': '278px',   ... ] 

So now this size can be set with <div clas="h-278px">...</div>

Update:

After completed many projects on top of TailwindCSS I learned that it's not very optimal to set spacing/w/h... in tailwind config if it's used only once. It's better to go with the custom class you can always use @apply in that class anyway.

Update 2021:

As of tailwind version 2.1 we can enable JIT and use arbitrary styles like this:

mb-[278px] 
like image 153
RomkaLTU Avatar answered Oct 04 '22 14:10

RomkaLTU