"TailwindCSS opts for the inclusion of prefexied utilities instead of relying

Trying to set the height of the div to h-2, with a class that includes height animation on medium devices.

The issue is that even though h-2 should be used on mobile, tailwindcss still uses h-20 instead.

Any thoughts on why this may be happening?

Here is the specific div causing the problem:

  <div className={`h-2 md:flex w-full text-white fixed bg-white mt-1 ${scrolling ? 'md:animationNav h-16' : 'md:animationBasisNav h-20'} dark:bg-gray-400`}></div>

Answer №1

The issue arises from the continued use of h-20 in tailwindcss on mobile devices instead of switching to h-2.

This problem occurs because you are applying the class h-20 (which sets the height to 20 across all screen sizes) rather than using md:h-20 (which sets the height to 20 only for screen size md and larger).

Furthermore, consider changing h-16 to md:h-16.

To address this issue, remember to add the md: prefix to classes that should apply solely to screen size md and above. This principle applies to other breakpoint prefixes as well. By default, all classes follow a mobile-first approach unless specified with a breakpoint prefix. For more information, refer to the Responsive Design section in the Tailwind CSS documentation.

Answer №2

My unique solution

Greetings, here's a suggestion for you to experiment with:


  <div className={`h-2 md:flex w-full text-white fixed bg-white mt-1 ${scrolling ? 'md:animationNav md:h-16' : 'md:animationBasisNav md:h-20'} dark:bg-gray-400`}></div>


You are now specifying that the height is 2 by default and 20 in medium devices.

Apply this approach across all your classes.

Step one: Specify the height for mobile devices

Step two: Include the classes for larger screens.

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

Layering digital sheets of paper and rearranging them with the help of CSS

I want to create a visual representation of a stack of paper sheets as a metaphor. The idea is to neatly stack the sheets on top of each other, with only the header of each sheet visible and the rest of the content covered. !-------------- | Sheet 1 +--- ...

Completed Animation with Callback in AngularJS CSS

Currently working with AngularJS and hoping to receive a notification upon completion of an animation. I am aware that this can be achieved with javascript animations such as myApp.animation(...), but I'm intrigued if there is an alternative method wi ...

obtain the content of a TextField element

In my React component that utilizes MaterialUI, I have created a simple form with a text field and a button: export default function AddToDo() { const classes = useStyles(); return ( <div style={{ display: "flex" }} ...

Error: Module not found '!raw-loader!@types/lodash/common/array.d.ts' or its type declarations are missing

I encountered a typescript error while building my NEXT JS application. The error message was: Type error: Cannot find module '!raw-loader!@types/lodash/common/array.d.ts' Below is the content of my tsConfig.json file: { "compilerOptions& ...

Tips for sending data to CSS in Angular

I have an Angular application where I need to calculate the width of an element and store it in a variable called finalposition. Then, I want to move this element to the left by (finalposition)px when hovering over it. How can I achieve this styling effect ...

Make sure the top edge of your Bootstrap 4 dropdown menu is perfectly aligned with the bottom edge of your

Trying to make a Bootstrap 4 navbar dropdown display right below the navigation bar, but it consistently shows slightly above the bottom edge of the navbar. Is there a way to make this happen without fixing the height of the navbar and using margin-top fo ...

Encountering an issue when trying to upload a file for the second time

I am currently working on a project where I need to upload an excel file and send it to an API using ReactJS. So far, I have been able to successfully send the file to the API. However, in my submit function, I want to reset the saved excel file from the s ...

Having trouble getting my Leaflet map to display even after meticulously following the quick-start guide

I am experiencing an issue where the map is not displaying at all, leaving a blank space where it should be. Despite following Leaflet's quick-start guide, I have been unable to determine the cause of this problem. Here is the code that I currently h ...

Do you think it's wise to utilize React.Context for injecting UI components?

I have a plan to create my own specialized react component library. These components will mainly focus on implementing specific logic rather than being full-fledged UI components. One key requirement is that users should have the flexibility to define a se ...

Switch up the order of a list in React with the click of a button

I just started working on my very first app using Javascript and React. My initial page displays a shopping list which is populated by making an API call to fetch items. Once the user clicks on the 'done' button (or should I use a checkbox inste ...

What's the best way to establish a Next.js global context without triggering a "Text content did not match" error?

I am currently working on a next.js App where I need to fetch SESSION data into a global context. This is how my code looks like: // _app.js const App = ({ Component, pageProps }) => { const start = typeof window !== 'undefined' ? window.se ...

Implement Webpack HMR in a Lerna React project with hoisting deployed

Can Webpack Hot Module Replacement (HMR) be used with a hoisted Lerna React project? The challenge arises because each Lerna React package (as shown below in the example structure) is compiled independently. When a webpack-dev-server is started on the mai ...

The node and npm versions are identical, yet the package.lock file differs

Our team is working on a React project with the same Node version (18.16.1) and NPM version (9.5.1). However, when I clone the repository and run `npm install`, I am getting a package-lock file that differs from the rest of the team's. What could be c ...

Limit file selection to images using MUI File Input

I am currently using MUI File Input in React for a file input element. The code I have works well, but I would like to restrict this file input to only accept images. How can I achieve this? Here is what I have done so far: const [locationImg, setLoc ...

The combination of two equal height elements with absolutely positioned child elements

I have a website that features a side-bar navigation and a main content pane, both enclosed within a container element. The content has its own unique background styling, while the menu adopts the background of the parent container. In situations where th ...

Building secure and responsive routes using next.js middleware

After setting up my routes.ts file to store protected routes, I encountered an issue with dynamic URLs not being properly secured. Even though regular routes like '/profile' were restricted for unauthenticated users, the dynamic routes remained a ...

Eliminating padding from columns results in the appearance of a horizontal scrollbar

I needed to eliminate the padding from the bootstrap grid column classes. So I went ahead and did just that .col-x { padding: 0; } However, this action ended up causing the entire layout to break as a horizontal scrollbar appeared. I've put to ...

What is the best way to shorten string values that exceed a certain length?

Here is an array list I have: $myarray = array( array( 'name' => 'File name 1 - type.zip', 'size' => '600KB', ), array( 'name' => 'File name 2 - type.pdf&a ...

Transforming a shared component in react to incorporate material theme

In my setup, I have two React projects - Parent and Common project. The Common project contains common components like header and footer that are shared between multiple projects. In the Parent project, I have a material theme defined and configured using ...

React js axios encountering CORS error while functioning perfectly in postman

I am encountering an issue in my Mern Stack Project where I can successfully create a Lesson using Postman, but when trying from my browser, I get a 500 error in the network tab. The console displays CORS error and another 500 error. I have tried various s ...