r/csshelp • u/pizayumyum • Mar 11 '20
Resolved Is it possible to have both a background gradient, as well as a background image at the same time?
Hey!
So, for my school project i'm attempting to have a both a background image (of an animated campfire with a navy blue background) & a colour gradient that "radiates" from the image, resulting in a fade from navy blue -> darker navy blue -> Black. Is it possible to do this? If so, how would i go about attempting such a feat? Any help is appreciated! <3
Edit: I forgot to add, the image should follow the scrolling of the page, so merely inputting an image wouldn't work :C
6
Upvotes
1
u/be_my_plaything Mar 11 '20
If so....
body{
position:relative;
background:black;
/* You can ignore the rest of the styling on body */
/* It was just added to make things clearer in the example */
padding:20px;
font-size:40px;
color:white;
text-align:center;
font-family:impact;
letter-spacing: 2px;
text-shadow: 5px 2px 2px #000000;
}
@media (orientation: landscape) {
body::before{
content:"";
position:fixed;
z-index:-1;
top:50%;
left:50%;
width:50vh;
height:50vh;
background:url(https://i.pinimg.com/originals/b9/67/d1/b967d1e281bd0aaca615e889386b0496.gif);
background-size:100% 100%;
transform:translate3d(-50%, -50%, 0);
}
}
@media (orientation: portrait) {
body::before{
content:"";
position:fixed;
z-index:-1;
top:50%;
left:50%;
width:50vw;
height:50vw;
background:url(https://i.pinimg.com/originals/b9/67/d1/b967d1e281bd0aaca615e889386b0496.gif);
background-size:100% 100%;
transform:translate3d(-50%, -50%, 0);
}
}
body::after{
content:"";
position:fixed;
z-index:-2;
top:50%;
left:50%;
width:100vw;
height:100vh;
background: #2123a8;
background: -moz-radial-gradient(center, ellipse cover, #2123a8 0%, #000000 80%);
background: -webkit-radial-gradient(center, ellipse cover, #2123a8 0%,#000000 80%);
background: radial-gradient(ellipse at center, #2123a8 0%,#000000 80%);
transform:translate3d(-50%, -50%, 0);
}2
1
u/Wazanator_ Mar 11 '20
Make the background a radial gradient https://www.w3schools.com/css/css3_gradients.asp
Add an image tag and have your css center the image both vertically and horizontally. I would make sure your image has transparency https://css-tricks.com/snippets/css/absolute-center-vertical-horizontal-an-image/