国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Key Points
Pick the reset to the next level
Custom attributes
Logical properties
New color function
Color adjustment
HWB color notation
gray() function
Summary
Frequently Asked Questions about Enable Upcoming CSS Features with PostCSS
Home Web Front-end CSS Tutorial Enabling Upcoming CSS Features with PostCSS

Enabling Upcoming CSS Features with PostCSS

Feb 21, 2025 am 09:30 AM

Enabling Upcoming CSS Features with PostCSS

Inherited in the previous article "PostCSS Guide: Improved Selectors and Media Query", this article will explore more PostCSS plug-ins that extend CSS functionality. The previous article focuses on improving the structure of style sheets by extending selectors and media queries, while this article will focus on how to implement new properties and values ??in the upcoming specification. The plugins described in this article implement different functions that can be used effectively together or individually according to your needs.

Let's start with my favorite plugin.

Key Points

  • PostCSS plug-in can be used to implement new properties and values ??in the upcoming CSS specification, effectively extending the functionality of CSS. These plugins can be used together or individually according to the needs of the developer.
  • PostCSS allows developers to use future CSS features before the browser is officially implemented. The postcss-initial plugin adds support for the initial value and all: initial combination, and the postcss-autoreset plugin automatically resets the style of block-level and component-level elements.
  • The
  • postcss-color-function plugin implements a new color() function that allows developers to use one or more "color adjuster" functions to modify the underlying color. The postcss-color-hwb plugin implements a new hwb() function to define the HWB color; the postcss-color-gray plugin implements the polyfill of the gray() function.
  • PostCSS provides a promising opportunity to adopt and evaluate new CSS features early. Developers are advised to write style sheets from a completely new perspective and list available features that can increase productivity.

Pick the reset to the next level

CSS3 introduces two nice features: initialvalue and all attribute. The initial value is used with the inherit and unset values, allowing you to reset the property to its original value. The all attribute is used as a shorthand attribute, which resets all attributes to one of these three states. While both are interesting in themselves, when used together, they allow you to quickly reset all styles of a specific element and prevent it from inheriting the styles of the page's parent element. This is another step in writing modular CSS!

Unfortunately, IE still does not support these two functions. However, as you may have guessed, there is a plugin that solves this problem.

postcss-initial Added support for initial values ??and all: initial combinations. Here is how it works:

.article {
  font-size: initial;
  color: initial;
  padding: initial;
  margin: initial;
}

Compiled to:

.article {
  font-size: medium;
  font-size: initial;
  color: #000;
  color: initial;
  padding: 0;
  padding: initial;
  margin: 0;
  margin: initial;
}

By default, it retains the original properties as well as initial for use by native browsers that support this feature.

In turn, the all attribute will be converted to a long list of reset attributes.

.container {
  all: initial;
}

will be converted to:

.container {
  /*  此處省略大量重置屬性  */
  all: initial;
}

(For the sake of space, the extended code after all: initial has been omitted)

If you use BEM or Suit, this plugin works well with postcss-autoreset, which will automatically reset the styles of block and component level elements.

Custom attributes

When working with layouts, we often need to share some values ??in the stylesheet. For example, your brand color can be used as a background for a button, a text color for a link, or a border for a block of text. Currently, to achieve this we need to repeat it multiple times each place where the color is used. This repetition makes it cumbersome to keep the palette consistent when changing colors in the application.

CSS preprocessors like Less and Sass have solved this problem with variables. Fortunately, W3C is working on a similar concept called custom properties. Although the same problem is solved, they work differently than variables in the preprocessor. Less and Sass variables are parsed at compile time. When you compile Less or Sass to CSS, the compiler looks for variable declarations corresponding to the current compile range and replaces each instance with the corresponding value. This means that the parsed value of a variable depends entirely on where it is used in the code. Custom properties, in turn, are defined for elements in the DOM and can only be accessed by their child elements. This means that the value of the variable depends on the position of the element in the DOM and can only be parsed at runtime.

You should be frowning or raising your eyebrows so far. If the value of a variable is only known at runtime, how does the PostCSS plugin parse it? The truth is, it can't. However, it does provide a way to use that subset of functionality. If we define all custom properties in the :root element, these properties will be available for all elements on the page. This means we can parse them at compile time.

Here is a simple example of what it might look like:

.article {
  font-size: initial;
  color: initial;
  padding: initial;
  margin: initial;
}

will compile to:

.article {
  font-size: medium;
  font-size: initial;
  color: #000;
  color: initial;
  padding: 0;
  padding: initial;
  margin: 0;
  margin: initial;
}

Note that the --font-size variable is undefined, so it is replaced with a fallback value of 20px. It is important here to keep all custom properties within :root. Properties defined elsewhere will be ignored because the plugin cannot handle them adequately. You can start here and you can extend its usage when more browsers start supporting it. Chrome has supported them since version 49.

Logical properties

If you have ever developed an international website that spans different writing direction cultures, you will know what it takes to maintain multiple versions of the interface (such as left to right or right to left). To meet this need, W3C introduced a new concept of logical attributes. A way to think about the physical direction (like right or left), but rather the logical direction—start and end. The specification is still in progress, but you can already try some of it with the postcss-logical-props plugin.

It supports the generation of left-to-right and right-to-left website versions using certain logical properties such as border-block-start and border-block-end, offset-block-start and offset-block-end. These properties are compiled into their left or right alternatives. You can instruct the plugin to compile the LTR and RTL versions of the stylesheet and then switch them in the application when the user changes the language.

For example, if you have the following CSS:

.article {
  font-size: initial;
  color: initial;
  padding: initial;
  margin: initial;
}

Calling the plugin with option { dir: 'LTR' } will produce the following results:

.article {
  font-size: medium;
  font-size: initial;
  color: #000;
  color: initial;
  padding: 0;
  padding: initial;
  margin: 0;
  margin: initial;
}

While using { dir: 'RTL' } will provide you with a mirror image:

.container {
  all: initial;
}

New color function

PostCSS provides a complete set of plugins that provide new features for handling colors.

Color adjustment

The

postcss-color-function plugin implements the new color() function. This function allows you to use one or more "color adjuster" functions to modify the underlying color. Each color adjuster can manipulate colors in a specific way.

Here are a few examples of how to use it:

.container {
  /*  此處省略大量重置屬性  */
  all: initial;
}

will compile to the following color:

:root {
  --text-color: red;
  --background: blue;
}

h1 {
  color: var(--text-color);
  font-size: var(--font-size, 20px);
}
button {
  background-color: var(--background);
}
The complete list of color adjusters can be found in the

specification. This plugin can be used very efficiently with custom properties. You can define a set of basic colors and calculate other colors based on them. This way, if you decide to change the base color, the rest of the palette will be updated accordingly.

HWB color notation

HWB stands for hue-whiteness-blackness, which is an alternative way to define color. It uses hue values ??from 0 to 360 to describe the color, and then adds 0% to 100% whiteness and blackness. This notation is similar to HSL and is easier to understand than RGB. The postcss-color-hwb plugin implements a new hwb() function to define HWB colors. Several examples:

h1 {
  color: red;
  font-size: 20px;
}
button {
  background-color: blue;
}

The following colors will be generated:

.text {
  border-block-start: 1px solid blue;
  text-align: start;
  padding-block-end: 10px;
  margin-block-start: 20px;
}

gray() function

The

CSS color module also introduces a convenient gray() function. It can be used to generate gray without specifying any redundant information, such as all three channels in RGB colors. postcss-color-gray The plugin implements the polyfill of this function and is very simple to use:

.text {
  border-left: 1px solid blue;
  text-align: left;
  padding-right: 10px;
  margin-left: 20px;
}

The above code will generate gray of different shades:

.text {
  border-right: 1px solid blue;
  text-align: right;
  padding-left: 10px;
  margin-right: 20px;
}

Summary

This is by no means a complete list of all available CSS plugins, but just a choice of some more interesting plugins. You can explore more plugins on postcss.parts.

CSS is booming, and PostCSS is booming. Yes, we are all eagerly awaiting native support for these new features by the browser, but PostCSS provides us with a promising opportunity to adopt and evaluate these features early. The overall advice here is to try to step back from the familiar usage of preprocessors and look at writing stylesheets from a new perspective. Try to list the available features that can increase your productivity and use them in your workflow. You may soon realize that these are exactly the features you've been missing.

Frequently Asked Questions about Enable Upcoming CSS Features with PostCSS

(The FAQ part is omitted here because the article is too long and does not match the pseudo-original goal. The FAQ part can be reorganized and rewritten as needed, but the original intention remains unchanged.)

The above is the detailed content of Enabling Upcoming CSS Features with PostCSS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
CSS tutorial for creating loading spinners and animations CSS tutorial for creating loading spinners and animations Jul 07, 2025 am 12:07 AM

There are three ways to create a CSS loading rotator: 1. Use the basic rotator of borders to achieve simple animation through HTML and CSS; 2. Use a custom rotator of multiple points to achieve the jump effect through different delay times; 3. Add a rotator in the button and switch classes through JavaScript to display the loading status. Each approach emphasizes the importance of design details such as color, size, accessibility and performance optimization to enhance the user experience.

Addressing CSS Browser Compatibility issues and prefixes Addressing CSS Browser Compatibility issues and prefixes Jul 07, 2025 am 01:44 AM

To deal with CSS browser compatibility and prefix issues, you need to understand the differences in browser support and use vendor prefixes reasonably. 1. Understand common problems such as Flexbox and Grid support, position:sticky invalid, and animation performance is different; 2. Check CanIuse confirmation feature support status; 3. Correctly use -webkit-, -moz-, -ms-, -o- and other manufacturer prefixes; 4. It is recommended to use Autoprefixer to automatically add prefixes; 5. Install PostCSS and configure browserslist to specify the target browser; 6. Automatically handle compatibility during construction; 7. Modernizr detection features can be used for old projects; 8. No need to pursue consistency of all browsers,

What is the difference between display: inline, display: block, and display: inline-block? What is the difference between display: inline, display: block, and display: inline-block? Jul 11, 2025 am 03:25 AM

Themaindifferencesbetweendisplay:inline,block,andinline-blockinHTML/CSSarelayoutbehavior,spaceusage,andstylingcontrol.1.Inlineelementsflowwithtext,don’tstartonnewlines,ignorewidth/height,andonlyapplyhorizontalpadding/margins—idealforinlinetextstyling

Styling visited links differently with CSS Styling visited links differently with CSS Jul 11, 2025 am 03:26 AM

Setting the style of links you have visited can improve the user experience, especially in content-intensive websites to help users navigate better. 1. Use CSS's: visited pseudo-class to define the style of the visited link, such as color changes; 2. Note that the browser only allows modification of some attributes due to privacy restrictions; 3. The color selection should be coordinated with the overall style to avoid abruptness; 4. The mobile terminal may not display this effect, and it is recommended to combine it with other visual prompts such as icon auxiliary logos.

Creating custom shapes with css clip-path Creating custom shapes with css clip-path Jul 09, 2025 am 01:29 AM

Use the clip-path attribute of CSS to crop elements into custom shapes, such as triangles, circular notches, polygons, etc., without relying on pictures or SVGs. Its advantages include: 1. Supports a variety of basic shapes such as circle, ellipse, polygon, etc.; 2. Responsive adjustment and adaptable to mobile terminals; 3. Easy to animation, and can be combined with hover or JavaScript to achieve dynamic effects; 4. It does not affect the layout flow, and only crops the display area. Common usages are such as circular clip-path:circle (50pxatcenter) and triangle clip-path:polygon (50%0%, 100 0%, 0 0%). Notice

How to create responsive images using CSS? How to create responsive images using CSS? Jul 15, 2025 am 01:10 AM

To create responsive images using CSS, it can be mainly achieved through the following methods: 1. Use max-width:100% and height:auto to allow the image to adapt to the container width while maintaining the proportion; 2. Use HTML's srcset and sizes attributes to intelligently load the image sources adapted to different screens; 3. Use object-fit and object-position to control image cropping and focus display. Together, these methods ensure that the images are presented clearly and beautifully on different devices.

Demystifying CSS Units: px, em, rem, vw, vh comparisons Demystifying CSS Units: px, em, rem, vw, vh comparisons Jul 08, 2025 am 02:16 AM

The choice of CSS units depends on design requirements and responsive requirements. 1.px is used for fixed size, suitable for precise control but lack of elasticity; 2.em is a relative unit, which is easily caused by the influence of the parent element, while rem is more stable based on the root element and is suitable for global scaling; 3.vw/vh is based on the viewport size, suitable for responsive design, but attention should be paid to the performance under extreme screens; 4. When choosing, it should be determined based on whether responsive adjustments, element hierarchy relationships and viewport dependence. Reasonable use can improve layout flexibility and maintenance.

What are common CSS browser inconsistencies? What are common CSS browser inconsistencies? Jul 26, 2025 am 07:04 AM

Different browsers have differences in CSS parsing, resulting in inconsistent display effects, mainly including the default style difference, box model calculation method, Flexbox and Grid layout support level, and inconsistent behavior of certain CSS attributes. 1. The default style processing is inconsistent. The solution is to use CSSReset or Normalize.css to unify the initial style; 2. The box model calculation method of the old version of IE is different. It is recommended to use box-sizing:border-box in a unified manner; 3. Flexbox and Grid perform differently in edge cases or in old versions. More tests and use Autoprefixer; 4. Some CSS attribute behaviors are inconsistent. CanIuse must be consulted and downgraded.

See all articles