Is there a way to dynamically adjust the overflow-y property based on the height?

Trying to make the overflow-y-visible property visible if the height is too small, otherwise using overflow-y-hidden with tailwind CSS and React.

Struggling to achieve this as I can't use sm, md, etc. for height like I can for width. Could someone please assist me?

Your help would be greatly appreciated!

Answer №1

To tailor a specific height of the viewport, you can utilize CSS media features:

.container {
  height:30px;
  overflow-y:hidden
}

@media (min-height: 100px) {
  .container {
    overflow-y:visible
  }
}
<div class='container'>
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>

Answer №2

Customize Tailwind media queries to Fit Your Needs:

You have the flexibility to create your own custom media queries by utilizing the raw key within your tailwind.config.js file. For instance:

module.exports = {
  theme: {
    extend: {
      screens: {
        'smh': { 'raw': '(min-height: 640px)' },
        // => @media (min-height: 800px) { ... }
       
        'mdh': { 'raw': '(min-height: 800px)' },
        // => @media (min-height: 800px) { ... }

        'lgh': { 'raw': '(min-height: 1240px)' },
        // => @media (min-height: 1240px) { ... }

       'xlh': { 'raw': '(min-height: 1600px)' },
        // => @media (min-height: 1600px) { ... }

      }
    }
  }
}

Any media queries defined using the raw key will be directly outputted, while any min and max keys specified will be disregarded.

Feel free to choose whatever names you prefer for your custom media queries - I used smh, mdh, lgh, and

xlh</cdoe>, but alternatives like <code>random
, something, or tallerscreen would work just as well. The important thing is that the name makes sense to you.


These customized responsive utilities function similarly to width-based media queries. For example, after adding your custom responsive utilities in the tailwind.config.js file, you can apply the following code to change the border color based on screen height:

<div class="border-4 border-blue-500 smh:border-red-500">test</div>

Check out this Tailwind Play link showcasing the above example: Link.


In a similar vein, you could use a setup like this to toggle the visibility of your overflow-y utility:

<div class="h-[5rem] overflow-y-hidden border-4 smh:overflow-y-visible">
  <div>Text.................</div>
  <div>Text.................</div>
  <div>Text.................</div>
  <div>Text.................</div>
  <div>Text.................</div>
</div>

When the window height exceeds 640px, anything overflowing from the div becomes visible. Conversely, if the window height is less than 640px, the overflow is hidden. Explore this scenario on Tailwind Play

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

Unable to modify the CSS properties of the titlebar in jQuery UI dialog

Is there a way to modify the background color of a jQuery UI dialog titlebar? Here is the code I am using: jQuery("#divId").dialog({ title: 'Information' }); jQuery("#divId .ui-dialog-titlebar").css("background-color", "red"); For m ...

Creating a sleek horizontal scrolling list with the least amount of rows using tailwindcss

Is there a way to create a 3-row list with horizontal scroll without the unwanted space between items? I've been using tailwindcss and grid to achieve this layout, but I'm encountering issues with spacing: https://i.stack.imgur.com/WeRyQ.png Cu ...

Tips for eliminating the shadow effect from a textbox using CSS

I need assistance with removing the shadowed edges on a textbox in an existing project. Can anyone provide guidance on how to remove this effect? Thank you for your help! ...

"Why does the React useState array start off empty when the app loads, but then gets filled when I make edits to the code

I'm facing a challenging task of creating a React card grid with a filter. The data is fetched from an API I developed on MySQL AWS. Each card has a .tags property in JSON format, containing an array of tags associated with it. In App.jsx, I wrote Jav ...

How to customize the appearance of an element within a shadow DOM

I am currently implementing a custom CSS style over an application without the ability to modify its code. Initially, the DOM structure looked like this: <div class="foo"> <div class="bar"></div> </div> and I ...

The dirtyFields feature in React Hook Form is not accurately capturing all the fields that are dirty or incomplete,

I am facing an issue with one field in my form, endTimeMins, as it is not registering in the formState. I have a total of four fields, and all of them are properly recognized as dirty except for the endTimeMins field. It is worth mentioning that I am utili ...

Storing a Promise in a Variable in React

As a newcomer to JavaScript/React, I am finding it challenging to grasp the concept of using Promise and async. To illustrate, consider the API call getSimById in a JS file that returns a Promise: export function getSimById(simId) { return fetch(simsUrl ...

Initiate an animation upon reaching a designated element using Jquery scroll event

Hey there! I've been trying to create an animation without using any plugins, but unfortunately, I haven't had much luck so far. Here's the code I've been working on. If anyone can help me figure this out, I'd really appreciate it ...

Incorporate a background only if the specified condition in AngularJS is met, utilizing ng-style

I'm struggling to incorporate a background url style based on a given condition. I tried using data-ng-style, but for some unknown reason, it's not working as expected. I'm not sure where I'm going wrong. data-ng-style="true : {'b ...

Sustaining component state in NextJS applications

I am facing an issue with my NextJS app where I have two distinct layouts for landscape and portrait modes. The parent page structure is as follows: <NavWrapper> <MyPage> </NavWrapper> The NavWrapper component handles the layout based on ...

Is there a way to place a Twilio call on hold without using a conference feature?

We're in the process of creating a calling web app with React and Node. This app will feature both incoming and outgoing calls. However, I'm encountering difficulties when it comes to putting a call on hold. Any suggestions or code snippets would ...

I can only successfully make an Axios GET request when I input the complete server path

I am currently working on an eCommerce project that has a backend developed using Node.JS and express, while the front end is built using React. I successfully connected the React frontend to the backend by setting the server address as a proxy in the pack ...

Issue with HTML and CSS where the header is displayed behind the rest of the content

I'm having issues with creating a fixed header for my webpage. It seems to be hiding behind the rest of the content on the screen even though I have tried adjusting the z-index without success. Here is a snippet of my HTML code: body { m ...

Implementing basic functionality with React Router

I am currently working on implementing React router and I have a main class named App where I need to call ExpenseApp. In order for ExpenseApp to function properly, it needs to receive some 'data'. Additionally, I want ExpenseApp to be the first ...

Hide the entire TR if Mysql equals zero

How can I apply the style "display: none;" to an entire TR if the result from row credits is 0? Should I achieve this using CSS or a MySQL query? <?php $username = "root"; $password = ""; $database = "aaa"; $mysqli = ne ...

jQuery form validation not functioning as expected

I'm attempting jQuery form validation but encountering issues with the desired functionality. I would like the border of an input to turn red when it's empty upon focus out. Alternatively, I aim to incorporate the "has-danger" bootstrap class to ...

Exploring Next.js routing using "next-connect" for nested routes

In my Next.js project, I have implemented an express-like structure of route->middleware->endpoint using the next-connect package. My route patterns include: /api/tours /api/tours/:id /api/tours/top-5-cheap /api/tours/stats /api/tours/monthly-plan ...

Unusual phenomenon of overflow and floating point behavior

HTML and CSS Output Example: <div id="float_left"> DIV1 </div> <div id="without_overflow"> DIV2 </div> CSS Styling: #float_left{ float: left; width:200px; background-color: red; } #wit ...

As I scroll, I hope the texts will stay fixed against the backdrop image

Is it possible to make the #home section fixed to the background while scrolling, including all the texts and buttons? I envision it like having texts embedded in an image. The text is located in the middle left of the page (let's keep this as default ...

Generating an <article> with React to encapsulate elements

I'm attempting to generate a list of 'cards', each consisting of three elements. The parent component, ItemCard, produces the following structure: <> <article> <ItemName data={items} /> ...