Color on background image not placing - html

I have been trying to place a transparent color on background image. The background image is working fine but the color is not placing.
I saw that the same question asked before. In my below code, I followed the same suggestion but not working for me.
How can I solve it?
body, html {
height: 100%;
margin: 0;
color:white;
background-image: url("../logo/background/1(2).jpg");
background-color: rgba(255,255,255, 0.5);
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}

To create an overlay effect, you can use linear-gradient property in background
body,
html {
height: 100%;
margin: 0;
background: linear-gradient(0deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5)), url(https://www.freecodecamp.org/news/content/images/2021/06/w-qjCHPZbeXCQ-unsplash.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
<body></body>

The background image is working fine but the color is not placing.
Yes because your background color is overlapped by background image.
To get a transparent layer over the image use the following code -
CSS
.background {
background:url('..');
position: relative;
}
.layer {
background-color: rgba(248, 247, 216, 0.7);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Also define width and height for background class.
HTML
<div class="background">
<div class="layer">
</div>
</div>

Related

How to disable backdrop-filter: blur from content inside a div? [duplicate]

This question already has answers here:
How to apply a CSS filter to a background image
(22 answers)
Closed 1 year ago.
I have a problem with this CSS property.
I created a modal containing Inputs and labels and I just want to blur the content on the background. The problem is that blur is applying also on everything inside a container including text and inputs.
I don't know how to fix this problem.
Here's my container code:
const StyledModal = styled.div`
position: relative;
overflow: auto;
z-index: 100;
width: fit-content;
max-height: fit-content;
padding: 47px 41px 61px;
display: flex;
border: 1px solid ${({ theme }) => theme.colors.primary};
border-radius: ${({ theme }) => theme.borderRadiusLarge};
background: linear-gradient(
180deg,
rgba(92, 192, 190, 0.4) 0%,
rgba(92, 192, 190, 0.4) 100%
);
backdrop-filter: blur(200px);
`;
Thanks in advance for all the helpful answers!
I created another element for the backdrop and gave it a negative index to be behind every other element.
.parent {
position: relative;
height: 250px;
width: 250px;
z-index: 0;
background-image: url('https://picsum.photos/id/237/200/300');
background-size: cover;
background-repeat: no-repeat;
}
.background {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
backdrop-filter: blur(20px);
z-index: -1;
}
<div class="parent">
<div class="background"></div>
Text not getting blurred
</div>

How does background-attachment work with its children?

I was looking for how to generate the new glass morphism effect with CSS3. Afortunatelly I found This article that make it happens. In the first method the article makes something like this (I wrote this code with the same structure and properties):
body {
min-height: 100vh;
background: url(./bg.jpg) no-repeat; /*<------ check that I'm using a background image*/
background-size: cover;
display: flex;
align-items: center;
justify-content: center;
background-attachment: fixed; /*<------ This is the most important part*/
}
.contenedor {
width: 500px;
border-radius: 10px;
height: 400px;
border: 1px solid #eee;
position: relative;
overflow: hidden;
background: inherit; /*<------- Here the ".contenedor" element inherits its parent's background*/
z-index: 2;
}
.contenedor::before {
z-index: -1;
content: "";
background: inherit;
position: absolute;
width: 100%;
height: 100%;
box-shadow: inset 0px 0px 2000px rgba(255, 255, 255, 0.5); /*<------- Here the magic happens making a blur inside */
filter: blur(10px);
}
With this HTML:
<body>
<div class="contenedor">
TEXT INSIDE
</div>
</body>
Now, I don't understand how the background-attachment works to mantain the background in the .contenedor element with inherit background.
I know that the background:inherit is to inherit all background properties from its parent, but what happen if I put
{
...
background: url(./bg.jpg) no-repeat; /*<------ check that I'm using a background image*/
background-size: cover;
background-attachment: fixed; /*<------ This is the most important part*/
...
}
instead inherit, It doesn't work.
PDT: Of course I understand the ::before pseudoclass to achieve the background and I'm using the first methos instead the second because is not compatible with Mozilla Firefox
Thank you all and sorry about my poor English

How to partially darken a background image using CSS?

.darken {
position: relative;
width: auto;
height: auto;
margin: 10px;
border-radius: 20px;
border: hidden;
padding: 20%;
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), no-repeat center top / cover;
}
<div class="darken" style="background-image: url("https://smorder.blob.core.windows.net/images/6/d9ffff37-79a2-44b2-aef4-6c8aadff1c6e");"></div>
But, it does not achieve what I want exactly. As I want to darken the left side of the image partially. I want to achieve something like this: http://prntscr.com/gj0hs8
Any ideas how to achieve this darkening effect?
linear gradient is treated as a background image too.
You can use it as an overlay if set first while using multiple background-image.
Mind the start/stop value, direction and to set 2 different colors in order to draw a gradient (tune provided example below to your needs).
A simple gradient always covers its container, no need to reset background-size to it
example below.
.darken {
position: relative;
width: auto;
height: auto;
margin: 10px;
border-radius: 20px;
border: hidden;
padding: 20%;
}
<div class="darken" style="
background:
linear-gradient(135deg, rgba(0, 0, 0, 0.8) 40%, rgba(0, 0, 0, 0) 70%) no-repeat center top ,
url(http://lorempixel.com/800/500/nightlife/7) 0 0 /cover ;">
test</div>
You need a div as overlay and give this one the gradient and it should work
Hope this might work
.darken {
position: relative;
width: auto;
height: auto;
margin: 10px;
border-radius: 20px;
border: hidden;
padding: 20%;
background-image: url("https://preview.ibb.co/fQxszF/security.jpg");
background-repeat: no-repeat;
background-size: cover;
}
.overlay::before {
position: absolute;
top: 0;
left: 0;
transform: translate(-230px, -60px) rotate(145deg);
content: '';
display: block;
width: 77%;
height: 65%;
background: rgba(0, 0, 0, 0.9);
}
<div class="darken overlay"></div>
Include the class overlay in the div.
Appreciate if useful.

How do I make a transparent background-color that is on top of a background-image go to bottom?

Okay, my problem is, I have a semi-transparent background-color on top of an image background. But when the computer screen is to big and page becomes longer vertically then horizontal the background-color stops after the content ends.
Example: background-color end before the end of the page.
I have looked everywhere and tried it all (height: 100%; height:100vh; bottom:0; margin:0; etc.). 100% does nothing, when using 100vh the background-color stops when I scroll down, bottom/margin:0; nothing.
The code my using is this.
html {
background: url(../images/back1.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
body {
background-color: rgba(0, 34, 62, 0.7);
margin: -0.5px;
font-family: verdana, sans-serif;
color: #b9c8d4;
text-align: center;
}
To see the website and the whole code go to: http://bienivitesse.com/juluwarlu/
If anyone knows any way to solve this, please let me know.
You have applied your main background to the html tag directly. While possible, it is not such a good idea to be styling it directly, always use the body or direct-descendants for the sake of good practice.
I think you can't stack a color on top of an image using the background property, but what you can do is - you can set the blue background using css pseudo-elements.
You will have to fiddle with the z-index property to get the divs to appear in the right order, so they won't be stuck under the color as well.
e.g.
html {
font-family: Arial, sans-serif;
}
.container {
background: url('http://placekitten.com.s3.amazonaws.com/homepage-samples/408/287.jpg') no-repeat center center/cover;
padding-bottom: 20rem;
position: relative;
z-index: 1;
}
.container::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 34, 62, 0.7);
}
.wrapper {
width: 70%;
margin: 0 auto;
z-index: 2;
position: relative;
}
.content {
padding: 4rem;
color: #fff;
background: purple;
z-index: 3;
}
<div class="container">
<div class="wrapper">
<div class="content">CONTENT</div>
</div>
</div>

How to create a overlay gradient background?

I've been looking for some answers to solve that issue I've found while developing a webpage. I'm trying to create a overlay gradient background like these examples I found on the web:
http://meridianthemes-demo.net/the-traveler/
http://demo.themeruby.com/innovation_personal/
My code currently looks like this:
.image-bg{
width: 100%;
height: 100%;
margin: 0px;
background: url('../images/background.jpg') center center no-repeat;
background-size: cover;
background-attachment: fixed;
&:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-image: linear-gradient(to bottom right, #e2dce1, #e8d5e4);
opacity: .8;
}
}
<body class="image-bg">
<div class="container" id="main">
<div class="logo">
<h1>Background Overlay Image</h1>
</div> <!-- ./ logo -->
</div> <!-- ./Container -->
...
Any ideas of how to change that code to something similar to the themes I've mentioned above?
Thanks in advance!
Instead of using a gradient of solid colors with opacity on the element, you can create a gradient with rgba (red/green/blue/alpha) colors, where one side of the gradient can be semi-transparent while the other is opaque.
I modified your code to show how to pull this off.
Also, you had nesting in your CSS (&:before) which doesn't work in native CSS - only a preprocessor like SCSS. I formatted it to work below.
.image-bg {
width: 100%;
height: 100%;
margin: 0;
background: url('http://i.imgur.com/NRdrfQw.jpg') center center no-repeat;
background-size: cover;
background-attachment: fixed;
}
.image-bg::before {
content: '';
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 1));
z-index: -1;
}
.container {
height: 800px;
}
<body class="image-bg">
<div class="container" id="main">
<div class="logo">
<h1>Background Overlay Image</h1>
</div>
<!-- ./ logo -->
</div>
<!-- ./Container -->
</body>
You should use rgba for the background gradient rather than opacity. Opacity will make every element within the body inherit that opacity.
As you're going to the bottom right in your example, I rotated the gradient by 135 deg in my example below..
I would also suggest you apply a position:relative to the container as the gradient will overlay any content within the body. Unless that's the desired effect?
.image-bg {
width: 100%;
height: 100%;
margin: 0px;
background: url('http://lorempixel.com/output/nature-q-c-1313-1259-2.jpg') center center no-repeat;
background-size: cover;
background-attachment: fixed;
}
.image-bg:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: linear-gradient(135deg, rgba(226, 220, 225, 0.37) 0%, rgba(232, 213, 228, 1) 100%);
}
.container {
position: relative;
}
<body class="image-bg">
<div class="container" id="main">
<div class="logo">
<h1>Background Overlay Image</h1>
</div>
<!-- ./ logo -->
</div>
<!-- ./Container -->