最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Using inherit as value in Tailwind v4 doesn't work - Stack Overflow

programmeradmin4浏览0评论

Since upgrading to Tailwind v4 where the config is CSS only I can no longer use inherit as a value. It creates the class but the actual value of the variable doesn't seem to work for some reason.

<script src="/@tailwindcss/browser@4"></script>
<style type="text/tailwindcss">
@theme {
  --radius-inherit: inherit;
}
</style>

<div class="w-[100px] h-[100px] bg-blue-500 rounded-3xl m-20">
  <div class="rounded-inherit bg-red-600">inherit</div>
</div>

https://play.tailwindcss.com/2VVorQvG0T?file=css

Since upgrading to Tailwind v4 where the config is CSS only I can no longer use inherit as a value. It creates the class but the actual value of the variable doesn't seem to work for some reason.

<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
<style type="text/tailwindcss">
@theme {
  --radius-inherit: inherit;
}
</style>

<div class="w-[100px] h-[100px] bg-blue-500 rounded-3xl m-20">
  <div class="rounded-inherit bg-red-600">inherit</div>
</div>

Is this a bug in Tailwind or am I doing something wrong?

Share Improve this question edited 5 hours ago rozsazoltan 7,6725 gold badges17 silver badges35 bronze badges asked 6 hours ago ChrillewoodzChrillewoodz 28.3k23 gold badges99 silver badges186 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Actually, if you take a look at the generated CSS, it perfectly creates what you asked for. The issue is that even when you replicate this with native CSS, it still doesn't work:

:root {
  --radius-inherit: inherit;
}

.rounded-inherit {
  border-radius: var(--radius-inherit);
}

.first {
  margin: 5rem; 
  border-radius: 1.5rem; 
  background-color: #3B82F6; 
  width: 100px;
  height: 100px;
}

.second {
  background-color: #DC2626; 
}
<div class="first">
  <div class="rounded-inherit second">inherit</div>
</div>

And if we omit the variable from the formula, it works:

.rounded-inherit {
  border-radius: inherit;
}

.first {
  margin: 5rem; 
  border-radius: 1.5rem; 
  background-color: #3B82F6; 
  width: 100px;
  height: 100px;
}

.second {
  background-color: #DC2626; 
}
<div class="first">
  <div class="rounded-inherit second">inherit</div>
</div>

So instead of using a variable, I would manually declare the class in TailwindCSS:

.rounded-inherit {
  border-radius: inherit;
}
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>

<div class="w-[100px] h-[100px] bg-blue-500 rounded-3xl m-20">
  <div class="rounded-inherit bg-red-600">inherit</div>
</div>

Is this a mistake? Yes, at least it's a shortcoming. I checked the bg-inherit class, and there, Tailwind declares the class perfectly without a var() variable, see here:

.rounded-inherit {
  border-radius: inherit;
}
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>

<div class="w-[100px] h-[100px] bg-blue-500 rounded-3xl m-20">
  <div class="rounded-inherit bg-inherit border-2">inherit</div>
</div>

/* generated */
.bg-inherit {
  background-color: inherit; /* without var() */
}

However, bg-inherit is a class created by default. I assume that all variables declared in @theme will appear in var(), so inherit cannot work anywhere, as it needs to be directly tied to the class, not from a separate variable. Perhaps you could create a development request to include rounded-inherit in Tailwind, similar to bg-inherit.

  • bg-inherit

And since inherit cannot be passed with a variable in CSS - as it is meant to express inheritance directly – I think it's also a mistake that Tailwind doesn't warn when declaring a variable in @theme.

发布评论

评论列表(0)

  1. 暂无评论