对多个页面进行CSS更改:合并代码?

时间:2019-03-28 11:55:17

标签: css wordpress

在我的Wordpress网站上,我只希望在某些页面上缩小特色图片。

因此,我可以为要更改的每个页面重复代码。这行得通,但是有点混乱。

.page-id-8 .page-header.has-featured-image {
    padding: 2rem 3.75rem;
}

.page-id-1018 .page-header.has-featured-image {
    padding: 2rem 3.75rem;
}

如何合并此代码?谢谢!

1 个答案:

答案 0 :(得分:0)

const path = require('path');
const webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
    mode: 'development',

    entry: './src/index.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    },

    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                }
            },
            {
                test: /\.html$/,
                use: [
                    {
                        loader: 'html-loader',
                        options: { minimize: true }
                    }
                ]
            },
            {
                test: /\.(scss|css)$/,
                use: [
                    {
                        // Adds CSS to the DOM by injecting a `<style>` tag
                        loader: 'style-loader'
                    },
                    {
                        // Interprets `@import` and `url()` like `import/require()` and will resolve them
                        loader: 'css-loader'
                    },
                    {
                        // Loader for webpack to process CSS with PostCSS
                        loader: 'postcss-loader',
                        options: {
                            plugins: function () {
                                return [
                                    require('autoprefixer')
                                ];
                            }
                        }
                    },
                    {
                        // Loads a SASS/SCSS file and compiles it to CSS
                        loader: 'sass-loader'
                    },
                ]
            },
            {
                test: /\.(png|svg|jpg|gif)$/,
                use: [
                    'file-loader'
                ]
            },
            {
                test: /\.(woff|woff2|eot|ttf|otf)$/,
                use: [
                    'file-loader'
                ]
            },

        ]
    },

    plugins: [
        new HtmlWebpackPlugin({
            template: "./src/index.html",
            filename: "./index.html"
        })
    ]
};

这些生成的类/代码吗?

您还可以使用

.page-id-8 .page-header.has-featured-image,
.page-id-1018 .page-header.has-featured-image {
    padding: 2rem 3.75rem;
}