Using CSS3 background-size within the `background` shorthand property results in syntax error
See original GitHub issueCSS3’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:
- Created 11 years ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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%"
.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;