The solution for re-calculation of z-index after css is packaged in Webpack is webpackz-index.

Source: Internet
Author: User

The solution for re-calculation of z-index after css is packaged in Webpack is webpackz-index.

Problems Found

Recently, when using Webpack to package css files, we found that the value of the packaged z-index is inconsistent with that of the source file z-index.

For example, the source file is on the left and the packaged file is on the right:

Even if you add! Important. After OptimizeCssAssetsPlugin calls cssProcessor cssnano for processing, it is also z-index: 2.

Therefore, it is likely that cssnano has been re-computed (cssnano is called rebase), and this computation is not accurate enough.

Because the packaged file contains two z-indexes and the second one, the z-index is 2.

Solution

Css nano classifies z-index rebase as unsafe instead of a bug. It is safe only when all css files on a single webpage are written to a css file and are not modified through JavaScript.

Reference: http://cssnano.co/optimisations/zindex/

The project extracts public css, A small z-index has been set for layout, so it is affected by cssnano z-index rebase.

Cssnano performs z-index rebase by default.

The unsafe (potential bug) optimization item is not enabled by default and should be friendly.

New OptimizeCssAssetsPlugin ({cssProcessor: require ('cssnan'), cssProcessorOptions: {discardComments: {removeAll: true}, // avoid cssnano recalculating z-index safe: true}, canPrint: false })

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.