[Feature Proposal]: Utilities for the CSS "inherit" keyword #1361
Replies: 17 comments 11 replies
-
+1. Thanks for raising this. I too, find myself extending Tailwind for this purpose in almost every project. |
Beta Was this translation helpful? Give feedback.
-
I would like to take this. We're getting hit at my job by the lack of native inherit support and I've been working on a PR to add support. What all properties should be granted inheritance? So far, I've added |
Beta Was this translation helpful? Give feedback.
-
Trying to figure out why I’ve never needed this — in the first example could you not use height: 100% for the child, or use flexbox to solve it? |
Beta Was this translation helpful? Give feedback.
-
[min-]height: 100% doesn't work. I tested it using the test case given by @lilisgeorge and added a border to each container to visually see the height of the child element. I think it fails because I know that's probably not the most technically accurate theory but that's how I've come to understand the problem. I've not looked at the code lately, but I believe whenever this came up, flexbox did not work due to the way the application is structured. <!-- My test case html showing only inherit works correctly-->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="/dist/tailwind.css">
<title>Hello, world!</title>
<style>
.parent {
min-height: calc(100vh - 3rem);
}
.parent > .child {
/* min-height: calc(100vh - 3rem); */
/* height: 100%; */
/* min-height: 100%; */
min-height: inherit; /* only this works */
}
</style>
</head>
<body class="p-4">
<div class="parent border-4 border-solid border-blue-600 p-2">
parent
<div class="child border-4 border-solid border-pink-500">child</div>
</div>
</div>
</body>
</html> |
Beta Was this translation helpful? Give feedback.
-
Hi again, This is a sample of a layout I was experimenting back then, where it fails with height: 100% or min-height: 100% but works with min-height: inherit. <body class="bg-green-300 relative pt-12">
<div class="bg-white h-12 absolute top-0 left-0 right-0 w-full">
header
</div>
<div class="main">
<!-- try replacing min-h-inherit with h-full or min-h-full to see it failing. For some reason it stops forcing to stretch full height -->
<div class="bg-gray-200 min-h-inherit">
Content
</div>
</div>
</body> .main {
min-height: calc(100vh - 3rem);
}
.min-h-inherit {
min-height: inherit;
} |
Beta Was this translation helpful? Give feedback.
-
I added this to my config file and think it would be a good addition to the default config
|
Beta Was this translation helpful? Give feedback.
-
Adding a use case for this: I want a child element to inherit the background colour. Specifically, I'm positioning something absolutely on top of another element and need that parent's background colour to cascade naturally and on hover.
|
Beta Was this translation helpful? Give feedback.
-
Hi there, I just wanted to share a use case I have faced. If you have a component that shouldn't predict part of its styling, you then have the following choices:
|
Beta Was this translation helpful? Give feedback.
-
I am using background-color: inherit; for dealing with components when I can't add a class to the top-level element easily. |
Beta Was this translation helpful? Give feedback.
-
Also it's need to fix child inside a parent with min-height |
Beta Was this translation helpful? Give feedback.
-
Another common scenario is that when you have the children element with the fixed position but still want to inherit the parent height. In this case, flex with flex-1 won't work. |
Beta Was this translation helpful? Give feedback.
-
I'm needing |
Beta Was this translation helpful? Give feedback.
-
Another scenario: Passing border radius down to child elements to avoid using overflow hidden on the parent (which can hide popup ui elements). |
Beta Was this translation helpful? Give feedback.
-
Another scenario: |
Beta Was this translation helpful? Give feedback.
-
As a workaround for now I've used You can also use with modifiers like |
Beta Was this translation helpful? Give feedback.
-
Really need this feature, here's another use case - text-transform: inherit whenever I want a to inherit the text transform from parent (because by default the all buttons are reset to text-transform: none from reset) My 2 cents: |
Beta Was this translation helpful? Give feedback.
-
I am in a project that desperately needs
How can I do this with tailwind? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
There are cases where using inherit css keyword would make more sense. Especially when you have a calculated css rule and need to inherit from that rather than duplicating it
e.g.
Instead of ...
... better have a dedicated utility
Keep up the good work.
Regards,
GL
Beta Was this translation helpful? Give feedback.
All reactions