How to add multiple images in background body [duplicate] - html

This question already has answers here:
Can I have multiple background images using CSS?
(8 answers)
Closed 6 years ago.
So I wanted to make a site where I could have the background have a header image of say 600px image, that being the "site background," then having the rest be a tiled image, as well as that I wanted the header background to adapt to movement, like background-position: center; CSS property.
I looked at W3 but their documentation is confusing. here
This is some code I tried:
background: url(bg.png) top, url(tile.png) repeat;
But I'm not sure how I'd be able to add background-position & height into that.

Short example:
.web {
width: 800px;
height: 1000px;
background-image: url(https://dummyimage.com/800x600/000/fff), url(https://dummyimage.com/800x300/555/fff);
background-size: 300px 200px, 300px 100px;
background-repeat: no-repeat, no-repeat;
background-position: center 0px, center 200px;
}
<div class="web"></div>

Related

Resizing image to autofit div in css [duplicate]

This question already has answers here:
Stretch and scale a CSS image in the background - with CSS only
(22 answers)
Resize image proportionally with CSS? [duplicate]
(18 answers)
Closed 3 years ago.
I am incredibly new to coding and am looking to autofit an image within a div in CSS. The code I've written just adds the background image in the CSS for the div, so haven't referenced the image file in the main HTML code.
Is there a way to resize the image within the div CSS or do I need to separate it out into div CSS and then image CSS (I hope I'm making sense!).
Or if there is a completely different way of doing it more efficiently please let me know - Any help would be greatly appreciated!
.test {
border: 2px dashed #0087F7;
background-color: #DCDCDC;
background-image: url('download.png');
background-repeat: no-repeat;
background-position: center;
}
You can use the properties contain and cover in background-size to manipulate the background's size. You can also set a percentage.
div {
width: 150px;
height: 50px;
display: inline-block;
border: 1px solid;
background: url("https://picsum.photos/150/150");
background-repeat: no-repeat;
background-position: center;
}
.cover {
background-size: cover;
}
.contain {
background-size: contain;
}
<div class="cover"></div>
<div class="contain"></div>

How do I center background image [duplicate]

This question already has answers here:
How to center a (background) image within a div?
(9 answers)
Closed 3 years ago.
So, I have a big image with logotype in the center, and thing that I asking for is how do I horizontally center the image, if screen width changes or varies between different devices?
I saw few solutions using "img" tag, but I need to know how to center background specifically.
body
{
background-image: url('website-bg.jpg');
background-repeat: no-repeat;
background-size: cover;
}
It's OK on big screen, but I am not sure that my screen big enough to display website with various resolutions.
You can use the background-position property, and set it to "center":
background-position: center;
Background Position Center will center your background image.
background-position: center;
body
{
background-image: url('website-bg.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}

background size: cover doesn't cover the whole screen [duplicate]

This question already has answers here:
How to remove the stripes that appears when using linear gradient property [duplicate]
(2 answers)
Closed 4 years ago.
I'm trying to set up a background-image to cover the whole screen, but it still doesn't cover the whole page, but only the upper part of it.
What am I doing wrong?
body {
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/104215/launch-day-boom_copy.svg");
background-repeat: no-repeat;
background-size: cover;
}
body { background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/104215/launch-day-boom_copy.svg"); min-height: 100vh; /* You must set a specified height / background-position: center; / Center the image / background-repeat: no-repeat; / Do not repeat the image / background-size: cover; / Resize the background image to cover the entire container */## > Heading ## }

CSS - centered image over a DIV with responsive background and full height image display [duplicate]

This question already has answers here:
Vertically centering image in a div tag [duplicate]
(4 answers)
Closed 7 years ago.
If you reed carefully this question you'll note IT'S NOT A DUPLICATED QUESTION. This one is about an image over a responsive background with full height image display. The answers related to the other questions are useless here. Thanks to jacob for his simple solution.
The issue:
I have a DIV with a responsive background. I'm trying to place a centered png "logo" over the DIV (or the background, if you prefer). That's what I have:
.divWithBG {
background-image: url(...);
background-size: contain;
background-repeat: no-repeat;
width: 100%;
height: 0;
padding-top: 45.45%; /* (h/w) x 100 */
margin-bottom: 30px;
}
.divWithBG img{
display: block;
margin: 0 auto;
}
¿What I need to do to place the image inside the div? Centered both, vertically and horizontally.
Many thanks in advance.
You could just make it simpler and use 2 background images. Multiple background images in CSS:
.divWithBG {
background-image: url("http://lorempizza.com/380/240") , url("http://lorempizza.com/2000/2000");
background-size: 50%, contain;
background-repeat: no-repeat, no-repeat;
background-position:center;
width: 100%;
padding-top: 45.45%; /* (h/w) x 100 */
margin-bottom: 30px;
}
<div class="divWithBG"></div>
The background image you want to be on top comes first in the background property.

Grey Blocks in background image [duplicate]

This question already has answers here:
Background Grey
(2 answers)
Closed 9 years ago.
I have set a background image on my website, in some browsers there come grey blocks in the background image. How do I solve this?
Website: http://haptotherapiemris.nl/
Here is my Css code:
.main {
margin: 0 auto;
background: transparent url(http://dansolution.nl/klanten/background/bg.jpg) repeat-y center top;
width: 1000px;
min-height: 1000px;
text-align: center;
background-repeat: no-repeat;
background-attachment: fixed;
}
if you mean the grey color to the right and left of your bg image... then you can remove it from the body { css file.
body {background-color:#595959; ...... }
to be
body {background-color:#ffffff; ..... }