Advertisement

Getting started with the @belongings CSS rule

The CSS @property is a great operation that brings additional control and flexibility to custom properties, often known as CSS variables. It was introduced as part of the CSS Houdini initiative, which was designed to give developers deeper access to the browser’s rendering engine. @property The rule means that you can define custom properties with […]

The CSS @property is a great operation that brings additional control and flexibility to custom properties, often known as CSS variables.

It was introduced as part of the CSS Houdini initiative, which was designed to give developers deeper access to the browser’s rendering engine. @property The rule means that you can define custom properties with specific types, default values, and even the ability to animate CSS cases.

In this article we will find out what @property The rule is because it is useful and the best way you can leverage it for your web activities.

What is it? @property For?

CSS custom properties, often known as CSS variables, have made sorts even more reusable. This means you can define a value once and use it everywhere in your stylesheet.

However, one limitation has been the inability to specify a property’s type or set default values ​​all at once in CSS. This means that any value can also be assigned to a convention property, which can lead to unexpected results and make it harder to take care of your sorts in some situations.

This is the position @property rule is available. This means that you can set a default value, provides a fallback value that could be used if the custom property is not explicitly set, allows the custom property to be animated, and defines a type for a convention property.

This promises that a variable {{a}} can best accept a chosen type of information, such as a size, a color, or a value.

The property type is printed with the syntax property. Accepts a string value that defines the value of the CSS type, as follows:

Put in order Description
Any trustworthy person values ​​for example, 10px, 2em, 50%, 3rem
Any trustworthy person values ​​for example, 1, 0.5, -3, 100
Any trustworthy person values ​​for example, 50%, 100%, 25%
Any trustworthy person values ​​for example, 10px, 50%, 2em, 75%
Any trustworthy person values ​​such as, #ff0000, rgb(255, 0, 0), rgba(255, 0, 0, 0.5), blue
Any trustworthy person values ​​e.g., url(image.jpg), linear-gradient(to correct, pink, blue)
Any trustworthy person url() values ​​for example, url(‘https://example.com/image.jpg’)
Any trustworthy person values ​​for example, 1, -10, 42
Any trustworthy person values ​​for example, 45 degrees, 0.5 turns, 1 rad
Any trustworthy person values ​​for example, 1s, 500ms, 0.75s
Any trustworthy person values ​​for example, 300 dpi, 2 dppx
Any trustworthy person values ​​e.g., rotate (45 degrees), scale (1.5), translate X (100 px)
Any trustworthy person values ​​e.g., –my-variable, custom-identifier
An inventory of trustworthy people values ​​for example, rotate (45 degrees) scale (1.5) translateX (100 px)

Example

Let’s say we now have a button phase. We’d like to set some defaults for this phase. Traditionally, we would use custom properties to set the background color and border radius of the button phase, like this:

.button {
  background-color: #fff;
  border-radius: 8px;
}

Or, use CSS variables to set values ​​once and reuse them throughout your stylesheet:

:root {
  --button-bg: #fff;
  --button-rounded: 8px;
}

What if we wanted to make sure that the background color is always a sound color value and the border radius is always a sound size value?

We can use the @property rule to establish the type of custom properties and set the default values.

To do this, we need to create a couple of custom properties defined with the following alternatives inside @property rule:

@property --button-bg {
  syntax: '';
  initial-value: #0D74CE;
  inherits: false;
}
@property --button-rounded {
  syntax: '';
  initial-value: 8px;
  inherits: false;
}

In this example we now have two custom properties that define the background color and the border radius of the button stage.

We use the syntax property to specify the type of custom property, while the initial-value property gadget the default value.

We also use the inherits property to specify whether or not the custom property inherits its value from the parent stage, in which case we set all to false to prevent inheritance.

Once set, we can use custom properties in our sorts, like this:

.button {
  background-color: var(--button-bg);
  border-radius: var(--button-rounded);
}

See @belongings CSS pen via HONGKIAT (@hkdc)
on CodePen.

In conclusion

The CSS @property the rule takes a very powerful step forward to custom CSS properties, or CSS variables. All number one and newer browsers already improve CSS properties @property rule.

Navigator Desktop Style Cellular style
Google Chrome 85 and later 85 and later
Mozilla Firefox 128 and later No longer supported
Safari 15.4 and later 15.4 and later (iOS)
Microsoft Edge 85 and later 85 and later
Opera 71 and later 71 and later
Samsung Internet 14.0 and later 14.0 and later

To summarize, CSS @property rule is a great operation and an excellent addition to the CSS language that allows you to write more maintainable and type-safe stylesheets. For those who haven’t already, check it out for your next effort!

The article Getting Beginning with CSS @belongings Rule first appeared on Hongkiat.

wordpress website Development

Source: https://www.hongkiat.com/blog/css-property-rule/

[ continue ]

wordpress Maintenance Plans | wordpress hosting

Learn more

Source link

See what others are saying about this...

Now you may not be the hero – your buyer is

April Sunshine Hawkins is a facilitator of the StoryBrand workshop, keynote speaker, and co-host of the Promoting Made Simple podcast (which has 2 million downloads). She helps companies simplify messaging and loves teaching industry leaders to leverage the StoryBrand...

Website Wizardry: The Art and Science of Crafting Digital Masterpieces…

Website Wizardry: The Art and Science of Crafting Digital Masterpieces In today’s digital realm, a captivating website is the cornerstone to success. Whether you’re a seasoned entrepreneur or a small business owner, your online presence is a powerful tool...

Higher Compression with Brotli – WP Mountain

Pssst… have you ever noticed that your web page loads a little faster than usual? Now it’s no longer just a figment of your imagination! We are happy to announce that we have implemented Brotli on all your websites hosted on WPMU DEV, giving you a...

Turbo Babe Anti-Aging Self Tanner

Product Name: Turbo Babe Anti-Aging Self Tanner Click here to get Turbo Babe Anti-Aging Self Tanner at discounted price while it’s still available… All orders are protected by SSL encryption – the highest industry standard for online security from...

The Easiest AI Equipment for Ecommerce & How They will Spice up Your Trade

As a one-woman solopreneur running her private trade, I’m ceaselessly looking for new AI apparatus to lend a hand save time, increase productivity, and convey about a better ROI. The ecommerce sector isn’t another. That’s why I’ve spent some...

Shogun Method by Derek Rake. Emotional Addiction, Not Seduction. + 17 Bonuses — Shogun Method

Product Name: Shogun Method by Derek Rake. Emotional Addiction, Not Seduction. + 17 Bonuses — Shogun Method Click here to get Shogun Method by Derek Rake. Emotional Addiction, Not Seduction. + 17 Bonuses — Shogun Method at discounted price while it’s...

How To Stay Your WordPress Website online Up-to-Date

For those who assemble a wordpress internet web page, maintaining it’s essential if you wish to have ongoing good fortune. A key part of this upkeep is regularly updating wordpress itself, your wordpress problems, and your wordpress plugins. Updating wordpress...

New Divi Starter Site for Weddings (Quick Install)

Divi empowers you to construct the most productive internet sites imaginable, and now, Divi Quick Sites takes site advent to a complete new degree. This progressive software we could someone, without reference to talent degree, generate a whole site in beneath two...

Books of spiritual solutions

Product Name: Books of spiritual solutions Click here to get Books of spiritual solutions at discounted price while it’s still available… All orders are protected by SSL encryption – the highest industry standard for online security from trusted...

How I finally relieved my back pain after 10 years…

Product Name: How I finally relieved my back pain after 10 years… Click here to get How I finally relieved my back pain after 10 years… at discounted price while it’s still available… All orders are protected by SSL encryption – the...

Getting started with the @belongings CSS rule

The CSS @property is a great operation that brings additional control and flexibility to custom properties, often known as CSS variables. It was introduced as part of the CSS Houdini initiative, which was designed to give developers deeper access to the browser’s rendering engine.…