The different breakpoints in Tailwind CSS will have an impact on the widths of

Currently, I am working on creating a side panel with a specific width of 90px for small screens (ranging from 320px to 640px). In order to achieve this, I customized a breakpoint in the tailwind.config.js. However, I encountered an issue where my new breakpoint (320px to 640px) is affecting all screen sizes above 320px. My UI is built using React.

Below is the React code snippet:

import '/src/assets/style/sidepanel.css'
function sidepanel(){
    return(
        <>
            <div className='sidepanel sm:w-1 xs:w-[90px] float-left'>

            </div>
        </>
    );
}
export default sidepanel;

Here is my tailwind.config.js:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {
      screens: {
        xsss:"0px", //0 to 160px
        xss: "160px", //160 to 320
        xs: "320px", //320 to 640
        sm: "640px",
        md: "768px",
        lg: "1024px",
        xl: "1280px",
        "smm": "200px",
        'height_login': {'raw': '(max-height: 260px)'},
      },
    },
  },
  plugins: [
    
  ],
}

Additionally, here is my sidepanel.css:


@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap");
@tailwind base;
@tailwind components;
@tailwind utilities;
* {
    margin: 0;
    padding: 0;
}
.sidepanel{
    background-color: rgba(83, 19, 72, 0.85);
    height: 100vh;
}

I have tried researching online and even experimenting with Tailwind arbitrary values, but unfortunately, I haven't found a solution yet. Ideally, I want the side panel width to be fixed at 90px only on small screens (320px to 640px), without affecting larger screen widths (above 640px).

Answer №1

The xs:w-[90px] class will impact screens that are 320px or larger. Essentially, it functions like this: @media (min-width: 320px) { width:90px }.

There are two ways to incorporate your concept:

1) For screens over 640px, you may want to consider a different style, such as: 'xs:w-[90x] sm:w-[140px]'

2) You have the option to adjust your tailwind.config.js as follows:

module.exports = {
  theme: {
    screens: {
      'xsss': {'min': '0px', 'max': '160px'},
      // => @media (min-width: 640px and max-width: 767px) { ... }

      'xss': {'min': '161px', 'max': '320px'},
      // => @media (min-width: 640px and max-width: 767px) { ... }

      'xs': {'min': '321px', 'max': '640px'},
      // => @media (min-width: 640px and max-width: 767px) { ... }

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

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

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

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

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

When using 'xs:w-[90px]', it will only take effect on screens larger than 320px but less than or equal to 640px

Answer №2

One of the key principles behind TailwindCSS is its mobile-first approach.

When working with TailwindCSS, you need to keep in mind the following guidelines:
0px - 320px ---> specify your styles for smaller screens
320px-640px ---> apply a width of 90px
640px+ ---> adjust your styles for larger screens

To implement this logic using TailwindCSS classes, you would use something similar to:

"width-[smaller screen value] xs:width-[90px] sm:[bigger screen value]"
.

Answer №3

When faced with this scenario, Tailwind CSS automatically generates rules prefixed with max-*. For detailed instructions, refer to the documentation here. To address your specific situation, consider implementing max-xs:w-[90px].

For a more aligned approach with Tailwind's principles, it is recommended to utilize xs:w-[90px] sm:w-[smth]

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

Designing a pair of elements within a single container

I am trying to achieve a layout where Element 1 and Element 2 can grow independently in height. However, I want the container's height to always match that of Element 2, while allowing Element 1 to grow as much as possible without exceeding the height ...

Understanding the mappings in a source map: Decoding the source map keys

Consider the following scenario with a stylesheet: .d1 width: 10px .d2 width: 20px When viewed using the nested output style, it leads to this css code: .d1 { width: 10px; } .d1 .d2 { width: 20px; } The source map (v3) indicates ...

Enabling CSRF protection between a ReactJS frontend and a Spring Boot backend across different domains

Our setup includes a frontend React JS application and a backend Spring Boot API with CSRF enabled, running on different domains. What is the most effective approach for passing the CSRF token between the REST API and the React application? ...

Manipulate container (div) to reveal and conceal

My jQuery was working fine until I added some more divs to my HTML. I'm now trying to toggle the opening and closing of a discussion container named discussionContainer with a click on the button replyButton. Any assistance would be highly appreciated ...

Bootstrap classes not aligning with individual elements

image My content is aligned with the text on the left and the form on the right, which is exactly what I intended. However, everything seems to be outside of my jumbotron container. Below is my HTML and CSS code. Your feedback is greatly appreciated. & ...

Tips for eliminating the excess space in material-ui's scrollable tabs

Check out this example for reference: https://material-ui.com/demos/tabs/#scrollable-tabs I'm looking to eliminate the additional space in the absence of an arrow icon: https://i.sstatic.net/IKdCf.png Appreciate any help. Thanks. ...

Using React alongside Three.js and OrbitControls across numerous canvases

I've successfully created a React + Three.js sandbox with multiple canvases displaying simple tetrahedron models. However, I am facing an issue where all instances are using Three.OrbitControls in the same way, causing all models to capture mouse even ...

Tips for automatically adjusting canvas size within a parent container

I am facing a challenge with a canvas element inside a div: <div class="preview"><canvas id="cropped" width="2480" height="2003"></canvas></div> The div block is smaller than the canvas. How ...

The process of converting RaphaelJS patterns into an SVG format

I am currently creating an interactive map using AngularJS and RaphaelJS. The entire SVG object is generated within a directive, and my goal is to assign different colors to each area on the map. Specifically, I want some regions to have a striped patter ...

Creating a Select Directory feature with React - A Step-by-Step Guide

I am in need of uploading all files from a folder to the server. I have been attempting to use a Select Directory window instead of selecting individual files. The standard method: <input type="file" webkitdirectory directory/> has not worked for ...

Fluid table that adapts to three columns on desktop screens, but switches to a single

Can someone help me with this issue? <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/> <div class="table-responsive"> <table class="table table-borderliness table-produ ...

Issue with Widget not correctly adding layers when configured through JSON configuration in React/Esri application

Recently, I started using ArcGIS Experience Builder and encountered an issue. While working on a React component to toggle the visibility of map layers in an Esri map, everything works perfectly when I hardcode the layers configuration. However, the probl ...

Creating a platform where your choices determine the results is my goal for a new website

My goal is to create a unique website that generates text based on responses to multiple choice questions. For instance, users can select symptoms from a list of options and receive recommended medicine at the end of the process. I'm wondering where ...

Having trouble with updating React state? The useEffect hook runs when attempting to change the state, but it seems to have the

Having worked with useEffect and its ability to trigger after a state variable has been updated, I am well-versed in its functionality. I'm currently drafting this post on my phone while away from home. Here's the setup I have: const [dateValue ...

Managing Autocomplete Functionality in React with Material-UI, Both with and without a Pre

I am in need of an Autocomplete feature that offers the following functionalities: If the initial value has an id greater than 0, then I want the autocomplete to default to the provided object. If the initial value has an id less than or equal to 0, then ...

What is the purpose of employing useMemo in the Material-UI autocomplete documentation?

My focus is on this specific demo in the autocomplete documentation. In the google maps example, there is a throttled function that is returned from a useMemo with an empty array as the second parameter. However, it raises the question of what exactly is ...

Is it advisable to incorporate JSS styles within a personalized React hook?

Struggling to create a reusable SearchBar Component that can hold its own state? Perhaps you've tried making a component for it, only to realize it needs two separate imports to function properly. The code might look something like this: import React, ...

Generate an array of LocalBusinessJsonLd Schema with the help of next-seo framework

Hey there, I'm currently working on implementing multiple localbusiness schemas in my next js application. To achieve this, I'm leveraging the next-seo package. import { LocalBusinessJsonLd } from 'next-seo' {locations.map((location) = ...

Exploring render props, leveraging Apollo, and enhancing JSX props using arrow functions

There are numerous examples illustrating how to utilize Apollo, such as: <Mutation mutation={YOUR_MUTATION} update={(cache, { data }) => { // execute operations to update the Apollo store }} > { mutate => ( <UI m ...

The alignment issue arises when using Grid-column-end with items of a set width

I am facing an issue with aligning an item in a specific column while maintaining a fixed width. When I attempt to right-align the item, it overflows the designated space. Removing the width attribute resolves the problem, but that is not a viable solution ...