Utilizing Tailwind CSS for creating a responsive layout on a Next.js application

I'm just getting started with Tailwind CSS and I decided to build the user interface of my nextjs application using a "mobile first" approach like everyone suggests. I got the flex direction and background color working perfectly on mobile screens, so it seems like Tailwind CSS is importing correctly into my nextjs application. However, when I resize the screen, the flex direction and background color of the navigation bar do not change accordingly.

Here's the code for the Navbar:

export default function Home() {
  return (
    <div>
      <Head>
        <title>Tailwind CSS Tutorial</title>
        <meta name="description" content="Generated by create next app" />
        <meta name="viewport" content="width=device-width, initial-scale=1"></meta>
        <link rel="icon" href="/favicon.ico" />
      </Head>

      <main>
        <header className="bg-gray-700 shadow-md sm:bg-red-900">
            <nav className="flex flex-col items-center sm:flex-row sm:justify-between sm:items-left">
              <div className="w-screen text-center px-5 py-2 text-white border-b sm:border-b-0 sm:w-auto">
                  W3Learn
              </div>
              <div className="py-2">
                  <a className="px-10 text-white" href="/html-lecture"> HTML</a>
                  <a className="px-10 text-white" href="/css-lecture"> CSS </a>
                  <a className="px-10 text-white" href="/js-lecture"> JS </a>
              </div>
            </nav>
        </header> 
      </main>
    </div>
  )
}

Here's my tailwind configuration:

module.exports = {
  mode: "jit",
  purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
  darkMode: false,
  theme: {
    extend: {},
    screens: {
    },
  },
  variants: {
    extend: {},
  },
  plugins: [],
}

Answer №1

The reason for the issue is due to the missing breakpoints configuration. I have added the necessary breakpoint lines in the screens section. These lines are usually included by default, and without them, the application should run smoothly without errors.

 'sm': '640px',
  // => @media (min-width: 640px) { ... }

 'md': '768px',
  // => @media (min-width: 768px) { ... }

 'lg': '1024px',
  // => @media (min-width: 1024px) { ... }

  'xl': '1280px',
   // => @media (min-width: 1280px) { ... }

  '2xl': '1536px',
   // => @media (min-width: 1536px) { ... }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using React to visualize data from Node.js in Chart.js

My Node.js application fetches a JSON object from a MySQL database and I want to display it in real-time using Chart.js and React. Here is the code snippet for fetching the JSON data from the MySQL database (script.js): const mysql=require('mysql&apo ...

How can Typescript help enhance the readability of optional React prop types?

When working with React, it is common practice to use null to indicate that a prop is optional: function Foo({ count = null }) {} The TypeScript type for this scenario would be: function Foo({ count = null }: { count: number | null }): ReactElement {} Wh ...

Developing a specialized collection of React components for efficient web development

I am currently in the process of developing my own library package for the first time. However, I have encountered a particular issue where despite successful compilation, the page fails to locate the module associated with my component within the library. ...

Changing the global type in TypeScript

Currently, I am incorporating two third-party TypeScript libraries into my project. Interestingly, both of these libraries expose a global variable with the same name through the Window interface. However, they offer different methods for interacting with ...

Dragging objects on a map is done using jQuery and it causes them to bounce

Currently, I am working on implementing the JQuery Draggable feature. My idea is to create a map where I can attach image Divs to it dynamically using Jquery. So far, I have been successful in adding the Divs and making them draggable around the map effici ...

Encountering a problem when trying to utilize material-ui icons in a React application

After installing the Material-UI core and icons packages using npm install @material-ui/core and npm install @material-ui/icons in my React app, I tried to use the FileUploadIcon. Here's how I imported it: import { FileUploadIcon } from '@materia ...

Conditional jQuery actions based on the selected radio button - utilizing if/else statements

This task seemed simple at first, but I quickly realized it's more challenging than expected. Apologies in advance, as Javascript is not my strong suit. My goal is to have the main button (Get Your New Rate) perform different actions based on whether ...

Develop a distinctive JavaScript solution that enables an image to appear in fullscreen upon loading the page, and then smoothly fade away after precisely

I have been trying to incorporate a feature on my Shopify frontage website where our logo appears fullscreen and then fades away or disappears after a few seconds, allowing people to access the rest of the website. However, I am facing difficulty in making ...

Emphasize entries in an index that match the currently visible content as you scroll

I have a table of contents in my HTML page with the CSS attribute position: fixed;. I want to emphasize the current reading position by highlighting it (bold or italics) as I scroll down the page. | yada yada yada ... 1. Secti ...

Using the Strikethrough Feature in React

Is it possible to apply a strikethrough effect to a checkbox's label text when toggled on and off? In my system development process, I've utilized various methods. What modifications should be made in the fComplete method for this feature to wor ...

Welcome to the awe-inspiring universe of Typescript, where the harmonious combination of

I have a question that may seem basic, but I need some guidance. So I have this element in my HTML template: <a href=# data-bind="click: $parent.test">«</a> And in my Typescript file, I have the following code: public test() { alert( ...

Adjusting the height of flex items to 100%

I'm currently diving into the world of flexbox by exploring various tutorials. Here's an example I created without utilizing Flex. Instead, I relied on float:left. Check out the example: https://jsfiddle.net/arhj8wxg/4/ I attempted to convert t ...

Attempting to establish a discussion board using MVC 5 on the ASP.NET platform

I'm currently facing a challenge while attempting to build a simple forum using ASP.NET MVC 5. Specifically, I am encountering an error message stating "The INSERT statement conflicted with the FOREIGN KEY constraint." Below, you can find the code sni ...

unable to display loading image prior to upload

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html lang="en"> <head> <title>Unique Prints</title> <meta charset="utf-8"> <meta name="viewport" conte ...

Tips for managing react-router rendering when the URL parameters have been modified

One central component manages all operations, and I aim to display this core component whenever the URL parameter shifts. To achieve this, I devised a Browser Router structure. function Router() { return ( <BrowserRouter> <Routes> ...

JavaScript: How to Build a Digital Grocery List with Browser Storage

Struggling with a tough exercise question, I could use some help deciphering it. https://i.stack.imgur.com/V5he2.png Here is how I've started the code: <!DOCTYPE html> <html> <head> <title></title> <script> fun ...

Aligning rows of checkboxes in React Material UI

Any suggestions on how I can achieve the following: I am looking to have two checkboxes, one for Android and one for IOS placed next to each other in a row. I have tried using Material UI FormGroup, Formlabel, and Checkbox components within a React form. ...

Trouble with setting up custom static route

Greetings! I am currently working on setting up my project in React and here is my current project structure: -public --w ---dist ----bundle.js ---index.html -server --server.js -src --app.js -webpack.config.js -package.json -.babelrc For my server, I am ...

React+vite application is unable to establish a WebSocket connection with a Spring Boot backend server

My React + Vite application is running on localhost:5173 port, while my Spring Boot is running on localhost:5729. Here is the code snippet from the App.jsx: import { useState } from 'react' import './App.css' function App() { const [ ...

What is the best way to create an oval-shaped background for a div element?

Can someone help me achieve an oval shape for my index page div? I tried using border-radius but the edges are too round for my liking. I am looking for a more specific result See the CSS code below for reference <div class="home-page"></div> ...