问题答案 12026年6月20日 12:11
How to set height of a div to 80% of the screen in TailwindCSS?
In Tailwind CSS, you can control the height of elements using height utility classes. To set a 's height to 80% of the screen, use the class to set its height to 100% of the viewport, then adjust it to 80% using relative units.However, Tailwind CSS does not provide a direct utility class for setting an element's height to 80% of the screen. You need to utilize custom utility classes or use CSS to achieve this. Here are two implementation methods:Method 1: Using Tailwind's Extended ConfigurationExtend the height utility classes in to add a custom class, such as , for setting the element's height to 80% of the screen height.Then, apply this new class in your HTML element:Method 2: Using Native CSSIf you prefer not to add custom classes in Tailwind's configuration, directly add a class in your CSS file:Then, use this class in your HTML file:Both methods effectively set the 's height to 80% of the screen. The choice depends on whether you prefer Tailwind's configuration for consistency or traditional CSS for simple customization.