Kosal Ang
Thu Jul 28 2022
Tailwind is a popular utility first CSS framework for rapidly building custom User Interfaces. It works by scanning all of your HTML files, JavaScript components, and any other templates for class names, generating the corresponding styles and then writing them to a static CSS file. You can learn more about Tailwind CSS here.
Next.js is a flexible React framework that gives you building blocks to create fast web applications. Next.js allow the web page to be rendered on the server, which is great for performance and SEO. You can learn more about Next.js here.
Start by creating a new Next.js project if you don’t have one set up already. You can create a new Next application using the command below.
1npx create-next-app my-project 2cd my-project 3
After your next project is created, Install tailwindcss
and its peer dependencies via npm
1npm install -D tailwindcss postcss autoprefixer 2
Then run the init command to generate postcss.config.js
and tailwind.config.js
.
1npx tailwindcss init -p 2
The above command will create two configuration files in your project.
1// tailwind.config.js 2/** @type {import('tailwindcss').Config} */ 3module.exports = { 4 content: [], 5 theme: { 6 extend: {}, 7 }, 8 plugins: [], 9} 10
1// postcss.config.js 2module.exports = { 3 plugins: { 4 tailwindcss: {}, 5 autoprefixer: {}, 6 }, 7} 8
Add the paths to all of your template files in your tailwind.config.js
file. So, in your tailwind.config.js file, add the following configuration.
1// tailwind.config.js 2/** @type {import('tailwindcss').Config} */ 3module.exports = { 4 content: [ 5 "./pages/**/*.{js,ts,jsx,tsx}", 6 "./components/**/*.{js,ts,jsx,tsx}", 7 ], 8 theme: { 9 extend: {}, 10 }, 11 plugins: [], 12} 13
In your ./styles/globals.css file, add the directives of tailwind CSS.
1@tailwind base; 2@tailwind components; 3@tailwind utilities; 4
To verify that everything will work as expected, replace all of the default code in pages/index.js with the following:
1export default function Home() { 2 return ( 3 <div class="flex justify-center"> 4 <div class="rounded-lg shadow-lg bg-white max-w-sm"> 5 <a href="#!" data-mdb-ripple="true" data-mdb-ripple-color="light"> 6 <img class="rounded-t-lg" src="https://mdbootstrap.com/img/new/standard/nature/182.jpg" alt="" /> 7 </a> 8 <div class="p-6"> 9 <h5 class="text-gray-900 text-xl font-medium mb-2">Card title</h5> 10 <p class="text-gray-700 text-base mb-4"> 11 Some quick example text to build on the card title and make up the bulk of the card's 12 content. 13 </p> 14 <button type="button" class=" inline-block px-6 py-2.5 bg-blue-600 text-white font-medium text-xs leading-tight uppercase rounded shadow-md hover:bg-blue-700 hover:shadow-lg focus:bg-blue-700 focus:shadow-lg focus:outline-none focus:ring-0 active:bg-blue-800 active:shadow-lg transition duration-150 ease-in-out">Button</button> 15 </div> 16 </div> 17 </div> 18 ) 19} 20
1npm run dev 2
Go to http://localhost:3000, you should get a result as below:
I hope you got something from this article that will help you in your journey. Thanks for reading!!!
Creating a beautiful menu bar using HTML, CSS, and JavaScript involves creating the structure with HTML
JavaScript uses asynchronous programming. Promises and `async`/`await` are two powerful features that facilitate asynchronous operations in JavaScript
There are scenarios where you might want to merge multiple enums into one, combining their respective values into a single type
JavaScript's closures and scope are fundamental concepts that significantly impact how code behaves
If you're looking to build a responsive sidebar with icons and expandable menus, this HTML and CSS template can serve as a great starting point
Arrays and objects in JavaScript is fundamental for managing and manipulating data
ECMAScript 6, also known as ES6 or ECMAScript 2015, introduced several powerful features that significantly enhanced the capabilities of JavaScript
To get the Monday and Sunday of the week, use the setDate() method to set the day of the month of a date to the Monday and Sunday
Generate all permutations of string and filter unique string by using JavaScript
JavaScript is a versatile scripting language primarily used for client-side web development. It enables interactivity and dynamic content on web pages.