csso icon indicating copy to clipboard operation
csso copied to clipboard

Background rewrites background-position

Open ai opened this issue 12 years ago • 13 comments

In:

.test1 {
  background: url(/1.png) no-repeat;
  background-size: 85px 85px;
}
.test2 {
  background: url(/2.png) no-repeat;
  background-size: 85px 85px;
}

Out:

.test1{background:url(/1.png)}
.test1,.test2{background-size:85px 85px}
.test2{background:url(/2.png)}

So in out third line background for .test2 rewrites background-size, which was combined for .test1 and .test2.

ai avatar Sep 25 '13 21:09 ai

:+1:

kossnocorp avatar Sep 25 '13 21:09 kossnocorp

Had the same issue recently.

kossnocorp avatar Sep 26 '13 09:09 kossnocorp

no-repeat shouldn't be removed, since it makes sense for the touch devices, when page is zoomed (default value is repeat).

drgullin avatar Nov 10 '13 23:11 drgullin

@ai what was expected?

CSSO has combined are common properties

.test1,.test2{background-size:85px 85px} .test1{background:url(/1.png) no-repeat} .test2{background:url(/2.png) no-repeat}

ArturAralin avatar Jun 18 '16 06:06 ArturAralin

@ArturAralin background-size will be lost in this case, since background resets all background-* properties

lahmatiy avatar Jun 18 '16 07:06 lahmatiy

@lahmatiy in this case how need to do it? What result i must get?

ArturAralin avatar Jun 18 '16 07:06 ArturAralin

In this case

.test1{background:url(/1.png) no-repeat}
.test2{background:url(/2.png) no-repeat}
.test1,.test2{background-size:85px 85px}

lahmatiy avatar Jun 18 '16 07:06 lahmatiy

Therefore partial overrides must be declared after common declarations?

ArturAralin avatar Jun 18 '16 07:06 ArturAralin

I also get odd results with transparent background:

.cls {
    background: transparent;
    background-position: 50% 0;
}

results in:

.cls{background:0 0;background-position:50% 0}

geekdevs avatar Aug 06 '16 13:08 geekdevs

@geekdevs It's correct. transparent = none = 0 0. 0 0 is the shortest correct background value that set defaults.

lahmatiy avatar Aug 06 '16 18:08 lahmatiy

The problem is that here I only set color, but position is changed instead. See better example why this is an issue below:

.cls1 {
    background: transparent;
    background-position: 50% 0;
}

.cls2 {
    background: #ccc;
    background-position: 50% 0;
}

becomes

.cls1,.cls2{background-position:50% 0}.cls1{background:0 0}.cls2{background:#ccc}

So in origin css position will rendered as background-position:50% 0, on compiled version it will be background-position:0 0

geekdevs avatar Aug 06 '16 19:08 geekdevs

Even if background stay transparent position will be 0 0. The problem here is wrong order but not a transparent -> 0 0 converting.

lahmatiy avatar Aug 06 '16 19:08 lahmatiy

yes, correct. This is what my whole point is about (it does not "merge" background-position with background correctly)

geekdevs avatar Aug 06 '16 21:08 geekdevs