CSS “decorations”

No Comments

A reader wrote to me the opposite day asking about this little bit of CSS they got here throughout in Wikipedia’s Frequent.css:

.mw-collapsible-leftside-toggle .mw-collapsible-toggle {
/* @noflip */
float: left;
/* @noflip */
text-align: left;

What’s that @noflip enterprise? That’s what they’re calling a “CSS decorator” and I believe that’s a nice time period for it. Actually they’re simply CSS feedback, however clearly there may be extra happening right here as these appear to be programmatic statements which have performance.

With out some type of CSS processing, these feedback will do nothing. Off the highest of my head, I’m not 100% positive what CSS processor is in use right here, however I believe it’s cheap to imagine that when it runs, it produces a “right-to-left” stylesheet that turns float: left into float: proper and text-align: left into text-align: proper.

I believe it’s value noting that it’s most likely smarter as of late to make use of the natively supported text-align: begin so that you simply don’t need to depend on CSS processing and alternate stylesheets that will help you. I don’t assume there’s a “logical” equal for float, sadly, however there could also be a solution to refactor the format (utilizing grid?) such that “flipping” is pointless. Though, wrapping components round a component is fairly distinctive to drift, so there won’t be a easy various right here.

Looking round slightly, it looks like the supply of /* @noflip */ is CSSJanus.

The repo suggests it’s made by Wikimedia, so I believe that’s a solved case. It seems to be just like the tech has made it’s solution to different issues, like a plugin for styled-components, a plugin for Elegant Textual content, and Salesforce even used it of their design system.

There’s one other processor known as css-flip (archived, from Twitter) that appears prefer it did the very same factor, and the README exhibits simply what number of properties may want this:

background-position, background-position-x, border-bottom-left-radius, border-bottom-right-radius, border-color, border-left, border-left-color, border-left-style, border-left-width, border-radius, border-right, border-right-color, border-right-style, border-right-width, border-style, border-top-left-radius, border-top-right-radius, border-width, box-shadow, clear, path, float, left, margin, margin-left, margin-right, padding, padding-left, padding-right, proper, text-align transition transition-property

It might have massively shocked me if there wasn’t a PostCSS plugin for this, and slightly looking turned up postcss-rtl, however alas, it’s additionally been deprecated by the proprietor.

This all began with speaking about “CSS decorators” although, which I assume we’re defining as “CSS feedback which have processor directives in them.” The one I personally use probably the most is that this:

/* prettier-ignore */
.cool {
to left,
pink 20%
pink 20%

I really like Prettier, but when I take the time to format a little bit of CSS myself for readability, I’ll chuck a /* prettier-ignore */ on the earlier line so it doesn’t mess with it.

Do you utilize any CSS decorators in your codebases?

The put up CSS “decorations” appeared first on CSS-Methods. You possibly can help CSS-Methods by being an MVP Supporter.

    About Marketing Solution Australia

    We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

    Request a free quote

    We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

    Subscribe to our newsletter!

    More from our blog

    See all posts

    Leave a Comment