+ 2

Can we give margin to background image only?

Plz explain

30th Mar 2018, 1:59 AM
Mayur Bhesaniya
Mayur Bhesaniya - avatar
2 ответов
+ 4
Your question is a bit vague but if you want content over a background image with margin only for the background image, then you have several possibilities, and to name 2 : - 2 different elements (like 2 <div>'s for your content and your background image, put a z-index of -1 in the CSS of your image - also 2 different elements, put an "absolute" position in your image CSS Then you're free to style the margin of your image without modifying the content over it.
30th Mar 2018, 3:32 AM
Nicolas Bonnet
Nicolas Bonnet - avatar
+ 1
Background images are default tiled (repeated along both vertical and vertical axis), so the only "real" way (appart tricky solutions as those specified by Nicolas Bonnet) to set "margin" would be to set specific 'background-repeat:no-repeat', 'background-position', and 'background-size' css properties to the element having the 'background-image' to be "marged"... You could also look at 'background-clip' css property... which could be set to the special value 'content-box' (background zone not covered by 'padding' of the element (if margin wanted for background image correspond to padding of content). https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip
30th Mar 2018, 4:28 AM
visph
visph - avatar