So here's my code:
background: url(images/my-image.png) no-repeat center center / cover;
This works fine on Chrome and Firefox but not on Safari for some reason?
I used to declare my background-size
on it's own line but as I understand it it should be possible to declare all properties in one line using a forward slash?
Any help would be much appreciated. Thanks.
To reduce the length of the CSS code we can declare background properties in one line through “Shorthand Property”. Through this property we can define different properties of background in a single line instead of using background-color, background-image and other properties in multiple lines.
The background-size CSS property sets the size of the element's background image. The image can be left to its natural size, stretched, or constrained to fit the available space.
The Modern Way When you work with background images, you may want an image to stretch to fit the page despite the wide range of devices and screen sizes. The best way to stretch an image to fit the background of an element is to use the CSS3 property, for background-size, and set it equal to cover.
As per the W3C Specs: A percentage is relative to the background positioning area. and background positioning area is one of either border-box or padding-box or content-box based on the background-origin property. Here you haven't specified any value explicitly for this and so its default value of padding-box is used.
As one line short hand code seems do unknown for safari browsers meaning of cover:
background: url(images/my-image.png) no-repeat center center / cover;
I faced the same issue before. And the following worked for all browsers:
background: url(images/my-image.png) no-repeat;
background-position: center;
background-size: cover;/*now this is known for the safari*/
background property has following attributes.
url
("image path")
bg-color
e.g transparent or any colorbg-img-repeat
e.g repeat
or no=repeat
bg-image-postion
vertical and horizontal e.g center center
bg-img-size
e.g cover
, contain
, 100%
, 800px
, or 200px 100px
(width and height) etcWe will write like this
background: url("images/my-image.png") transparent no-repeat bottom center / cover;
background-size: cover; /*for safari we can add this sperately*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With