Move DNN Styles Into Cascade Layers to Allow Modern CSS Styling #6778
Replies: 4 comments 6 replies
-
|
If you would like to see a working website with a TailwindCss v4.1.14 theme that has a hacked (working) solution in place as a demonstration, go here We've manually modified the [/Resources/Shared/stylesheets/]
This one change solved at least 3 major issues as well as dozens of minor/glitchy visual problems in the DNN backend.
|
Beta Was this translation helpful? Give feedback.
-
|
As we now have a version default.css created from an scss source, isn't building your own version (and not loading the "default" default.css) the best option anyway? |
Beta Was this translation helpful? Give feedback.
-
|
If you are not logged in, the problem is minimal or almost non-existent. Well, unless you've got a vendor's modules on the page with old, leaky, or poorly written CSS (and HTML) in play. If you are logged in, see the screenclip below, every line above the highlighted Aperture skin.css is a CSS file contributed to the page by a clean install of DNN v10.01.02 - currently without a @layer, and therefore all in the
|
Beta Was this translation helpful? Give feedback.
-
Option 1 - Inline-Style with @import ... layer(name);Note: Opt 2 is in a reply below One possible solution I've been thinking about would require a fair amount of effort, though in some ways stays conceptually pretty simple. Since the only way to specify a layer is in an We have to modify or extend the Client Resource Management API to provide a new output option. Instead of the result like you see above, a bunch of <style>
@import url(/admin/menus/ModuleActions/ModuleActions.css?cdv=127) layer(base);
@import url(Resources/Shared/stylesheets/dnnicons/css/dnnicon.min.css?cdv=127) layer(base);
@import url(/Portals/_default/Skins/_default/WebControlSkin/Default/GridView.default.css?cdv=127) layer(base);
...
</style>I understand (at this time) this might be a slight performance hit since the DNN would need to add settings for this. It also seems obvious we'd need a default layer to throw them all into and additionally a way to select/match/assign? others to specific layers (e.g. reset, components, utilities, or whatever is needed). |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Reference: MDN Core CSS Features - Cascade Layers
Note that the issues here are not unique to Tailwind CSS v4 or DNN. Any system that uses CSS Cascade Layers on top of an existing framework that does not already use layers ends up with ALL of its CSS in the
implicit outer layerand an unbeatable specificity.Credit for raising the issue/need: #6686 - [Enhancement]: Wrap default.css in @layer to work with Tailwind 4
The primary reason for difficulties in using Tailwind CSS v4 with a pre-cascade-layers (legacy) framework (e.g. DNN, WordPress, etc.) stems from Tailwind v4's reliance on native CSS Cascade Layers, a feature that legacy frameworks and their extensions do not natively support or integrate with effectively.
Please keep in mind, this is not about TailwindCss v4. DNN currently prevents the use of the modern CSS Cascade Layers feature and it needs to be addressed.
Here's why this creates incompatibility:
Unlayered Styles Priority: In CSS, unlayered declarations (styles not explicitly placed within a @layer rule) have higher priority than declarations within a layer, regardless of their order in the stylesheet. Legacy frameworks' existing styles are largely unlayered.
Tailwind v4's Use of Layers: Tailwind CSS v4 utilizes native cascade layers to organize its utility classes and ensure proper cascading behavior. This means Tailwind's styles are placed within layers.
Conflict in DNN and other legacy frameworks: When Tailwind v4 styles (layered) are used alongside the framework's unlayered styles, the unlayered styles often override Tailwind's intended styling, even if Tailwind's rules appear later in the stylesheet or have the same specificity. This can lead to unexpected visual inconsistencies and broken layouts, particularly in the legacy framework's admin or backend area where numerous unlayered styles are in play. In DNN this borders on unusable for on-page things like Module Settings.
Addressing the Issue:
While directly integrating Tailwind v4's layered approach into DNN or WordPress or any legacy framework can be challenging, potential workarounds or solutions might involve:
Wrapping DNN Styles in Layers: Attempting to wrap all of DNN core, admin, extension, module styles within @layer rules. Though not technically difficult, the results could potential introduce complex and potentially fragile results that may require additional work for the backend.
Using
!important: Applying the !important modifier to classes in layers can force them to take precedence, but this can lead to difficult-to-manage CSS and conflicts with other !important declarations. It might be prudent to remove all occurrences of !important in the framework's CSS and fix the precedence issues correctly using other logic, cascade layers (nesting), or other options.Exploring Compatibility Builds or Tools: Some projects or tools might emerge to provide better compatibility between Tailwind v4 and legacy frameworks, potentially by adjusting how styles are loaded or processed. For example DnnCssInclude() could add features that would introduce a default target layer when not specified - as well as handle a passed in layer parameter. However, since the HTML LINK element does not yet support a
layer=""attribute, this becomes a modification process that may involve storing/caching multiple versions of CSS files. Too early to speculate, but imagine:default.css,default.min.css,default.layer.css, anddefault.layer.min.cssand DNN loads the correct one based on Host, Site (or Theme) settings. **Repeating from above, I am just reiterating this for clarity: This is not about TailwindCss v4. DNN currently prevents the use of the modern CSS Cascade Layers feature and it needs to be addressed.
** One future option is that it is likely within the next 1 to 3 years, the HTML spec will add an attribute to the
<link>element. You can read about this here. Note that this is a massive discussion covering a lot of ground.The HTML Standard - Issue 7540 - Allow authors to apply new css features while linking stylesheets
whatwg/html#7540
Beta Was this translation helpful? Give feedback.
All reactions