V
V
Vladislav2019-08-07 00:38:35
css
Vladislav, 2019-08-07 00:38:35

Webpack optimization of styles, classes?

At the entrance there are such classes

.class_1 {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}

.class_2 {
    position: absolute;
    top: 0;
    bottom: 0;
}

How to get the output
.class_1, .class_2 {
    position: absolute;
    top: 0;
    bottom: 0;
}

.class_1 {
    right: 0;
    left: 0;
}

UPD:
I tried to use postcss-merge-selectors but it works so crookedly that it hurts to watch

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
inkShio, 2019-08-07
@inkShio

postcss-merge-selectors - I didn't delve into the essence of this plugin, but it seems to me that it works if your selectors are different, and the styles inside are the same, then it merges them.
in your case it is better to use extend

.class_1 {
    @extend .class_2;
    right: 0;
    left: 0;
}

.class_2 {
    position: absolute;
    top: 0;
    bottom: 0;
}

or in this way
%position {
    position: absolute;
    top: 0;
    bottom: 0;
}

.class_1 {
    @extend %position;
    right: 0;
    left: 0;
}

.class_2 {
    @extend %position;
}

A
Anton Spirin, 2017-12-14
@Meyz

Because the display rule for your component is set by the css selector , not the key of its own style property .
This is how it will work:

var leftMenu = document.querySelector(".left-menu");
var displayValue = window.getComputedStyle(leftMenu,null).getPropertyValue("display");
console.log(displayValue === 'none');

Y
Yustas Alexu, 2017-12-14
@Yuxus

leftMenu.style.display are inline styles. If you set styles via CSS, they will not appear in the style property of the element. They need to be read differently.

O
Oleg, 2017-12-14
@politon

if(screen.height =< 1000 )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question