question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using CSS3 background-size within the `background` shorthand property results in syntax error

See original GitHub issue

CSS3’s new background-size property can be included in the background shorthand declaration by separating it from the background-position specification with a forward slash, like this:

div {
    background: url('/path/to/image.png') left center / contain no-repeat;
}

The result is a syntax error, though, with the parser obviously choking on the / contain part—removing it also makes the error disappear.

Of course it is possible to work around this issue by escaping the entire value of the background property with ~"…", but it would be really nice to be able to use the default syntax without restrictions.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
seven-phases-maxcommented, Jan 8, 2015

@gpv-dev

Your result is expected if you compile w/o --strict-math=on option. By now for such statements (with a one or two exceptions, e.g. font property) you have to use either --strict-math=on or put some escaping for /, e.g.: ~"0/100%".

0reactions
juukiecommented, Nov 30, 2017

Thanks @seven-phases-max, got it working: url(/assets/img/logos/foo.png) 0 0 / ~"167px auto" no-repeat; url(/assets/img/logos/foo.png) 0 0 / contain no-repeat;

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues with "background-position" in "background" shorthand ...
I was attempting to use the background shorthand property to specify background-size , background-repeat , and background-color , but kept ...
Read more >
background - CSS: Cascading Style Sheets - MDN Web Docs
The background shorthand CSS property sets all background style properties at once, such as color, image, origin and size, or repeat method.
Read more >
CSS Background Shorthand Property - WebFX
The background shorthand property is a way to specify the values of multiple CSS background properties in a single declaration. Example
Read more >
CSS Background Shorthand - W3Schools
Use the shorthand property to set the background properties in one declaration: ... whether a background image is fixed or scrolls with the...
Read more >
CSS Background Shorthand Tutorial - Udacity
The code provided the page with the desired result. However, it did so on five separate lines calling multiple properties in the process....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found