Css Background image blur outside from div - html

I have a div with a background image and a very high blur applied on it. My problem is that the blur effect is also a bit outside from the div container, which is absolute positioned.
Problem is shown here
<div class="p-2 position-relative bg-grey-secondary border-0 rounded-2 card">
<div class="position-absolute w-100 h-100 bg" style="background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/7/70/Solid_white.svg/2048px-Solid_white.svg.png);"></div>
</div>
<style>
div > div {
top: 0;
bottom: 0;
left: 0;
right: 0;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
filter: blur(13px);
opacity: 30%;
mask-image: linear-gradient(to top, transparent, black);
}
</style>
div>div {
top: 0;
bottom: 0;
left: 0;
right: 0;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
filter: blur(13px);
opacity: 30%;
mask-image: linear-gradient(to top, transparent, black);
}
<div class="p-2 position-relative bg-grey-secondary border-0 rounded-2 card">
<div class="position-absolute w-100 h-100 bg" style="background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/7/70/Solid_white.svg/2048px-Solid_white.svg.png);"></div>
</div>

Not sure but try this and I request please write your question clearly
mask-image: linear-gradient(to top, transparent, black);

Not sure me too about the request but I'll try to answer, otherwise please provide a clearer example of the result you want to obtain...
Are you looking for a glass effect blurring the background?
backdrop-filter: blur(2px);
Your CSS will look like this:
<style>
div > div {
top: 0;
bottom: 0;
left: 0;
right: 0;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
/* comment blur filter, in this case not necessary*/
/* filter: blur(13px); */
opacity: 30%;
mask-image: linear-gradient(to top, transparent, black);
/* add filter to blur the objects behind the background */
backdrop-filter: blur(2px);
}
</style>
Some hints: to modulate the glass effect mantain the backdrop-filter at low values and change the opacity of the object you are applying the filter.
Here is a live example of the effect.
The codepen here:
https://codepen.io/gesteves/pen/PwRPZa
Find the full explanation here, containing differences and usage of both blur filter and backdrop-filter and how to obtain the glass effect:
https://css-tricks.com/almanac/properties/b/backdrop-filter/

Related

2 stacked div's with background gradients, not displaying properly

I have an issue where I want to have to divs that act as a background. they basically wrap the entire page. both have the same gradient set as their background-image. the problem is that on div displays the gradient perfectly fine, but the other is just white.
html:
<div class="bg bg-base">
<div id="bg-animation" class="bg bg-animation">
<div class="layer-content">
<!--content here-->
</div>
</div>
</div>
CSS:
.bg {
background-position: bottom center;
background-repeat: no-repeat;
background-size: cover;
width: 100%;
position: absolute;
}
.bg-base {
background-image: linear-gradient(to left bottom, #5533ff, #008dff, #00bdff, #00e0dd, #a4fbc9);
}
.bg-animation {
background-image: linear-gradient(to right top, #5533ff, #008dff, #00bdff, #00e0dd, #a4fbc9);
}
.layer-content {
width: 100%;
position: relative;
}
I'm doing some opacity animations with the top gradient, that's why I need 2 of them on top of each other. but if say, I set the opacity of the top gradient to 0, the bottom one isn't there. if I add a height: 5000px; to the bg-base, it does show up.
Kill the absolute positioning:
https://jsfiddle.net/cathead/1nbjdp05/4/
.bg {
background-position: bottom center;
background-repeat: no-repeat;
background-size: cover;
xposition: absolute;
width: 100%;
}

Trying to add linear-gradient to a data base image, can i use a db image on css?

So first im trying to create a linear gradient on a card, so i have a div that is a link, and has a background image. so what i want to do is to show the image without text and when i hover change the background to a darker tone and show the text.
or is there a way to use: background-image:
url(<%= project.photos.first %> in my css file?
Tried to use css to set only the linear gradient to the background and so far is no results.
Even tried java script to select the div and add the linear-gradient in this format:
linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.3))
But is always replacing the url and i lose my image at the end.
My Home page:
<div class="col d-flex align-content-center flex-wrap card-category home-card-light" style="background-image: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0)), url(<%= project.photos.first %>)">
<h2 class="card-title"><%= project.title %></h2>
</div>
<% end %>
The CSS
.home-card-light {
height: 430px;
width: 720px;
background-size: contain;
background-repeat: round;
margin-right: auto;
margin-left: auto;
&:hover {
height: 430px;
width: 720px;
background-size: contain !important;
background-repeat: round !important;
background: linear-gradient(
rgba(23,34,40,0.5),
rgba(13,23,54,0)
) !important;
}
}
The code posted is creating the linear gradient but replacing the image with it.
You can do this using :after
.img-gradient {
position: relative;
display: inline-block;
}
.img-gradient:after {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: inline-block;
background: -webkit-linear-gradient(top, rgba(23,34,40,0.5) 0%, rgba(220, 66, 37, 0.5) 100%);
}
.img-gradient img {
display: block;
}
<div class="img-gradient">
<img src="https://www.w3schools.com/bootstrap/la.jpg" width="400" />
</div>

background image grayscale

I for background on my website I use colors and at top I have an image.
I want to make this image black and white with css:
body {
background: url('background.jpg') center top no-repeat;
-webkit-filter: grayscale(100%);
}
but this code make whole site grayscale
I also tried to put site content to new div with style -webkit-filter: none; but it don't work neither.
There's another solution without using an overlay div using background-blend-mode.
This is supported among all major browsers https://caniuse.com/?search=background-blend-mode (except IE)
background-color: rgba(255,255,255,1);
background: url('background.jpg') center top no-repeat;
background-blend-mode: luminosity;
you can try a different div overlayed over <body>
like this
#overlay {
background: url('background.jpg') center top no-repeat;
-webkit-filter: grayscale(100%);
z-index: -1;
opacity: 0.5; /*make it as your requirement*/
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
and your html will look like
<body>
<div id="overlay"></div>
<!-- other body elements -->
</body>
This is block style in jsx syntax (from reactjs-application). I have no clue what is going on there, but it seems to work
style={{
minHeight: '100vh',
backgroundPosition: 'center',
backgroundSize: 'cover',
backgroundImage:"linear-gradient(black, black), url('images/bgimage.jpg')",
backgroundBlendMode: 'saturation'
}}

How to remove white border from blur background image

How to remove the white blur border from the background image.
<div class="background-image"></div>
CSS, i tried adding margin:-10px but it doesn't work
.background-image {
background: no-repeat center center fixed;
background-image: url('http://www.hdpaperz.com/wallpaper/original/windows-8-wallpapers-2560x1600-2311_1.jpg') ;
background-size: cover;
display: block;
height: 100%;
left: -5px;
top:-5px;
bottom:-5px;
position: fixed;
right: -5px;
z-index: 1;
margin:0px auto;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
http://jsfiddle.net/maio/8wq132nd/1/
The simplest way to do it is by adding transform: scale(1.1).
Try it here.
#overlay {
position: fixed;
left: 22.5em;
top: 3em;
height: 75%;
width: 50%;
background: url("https://s-media-cacheak0.pinimg.com/originals/ae/b4/c5/aeb4c53cab2b550187644af503a0f17e.png");
background-size: cover;
filter: blur(9px);
transform: scale(1.1);
}
Up-to-date answer (2022)
You can achieve this effect with just css by using backdrop-filter on an overlaying element.
.blurred::after {
content: "";
position: absolute;
width: 100%;
height: 100%;
backdrop-filter: blur(10px); /* apply the blur */
pointer-events: none; /* make the overlay click-through */
}
.blurred {
position: relative;
width: 500px;
height: 300px;
background: no-repeat center center;
background-image: url('https://besthqwallpapers.com/Uploads/26-5-2019/94041/thumb2-tesla-model-x-2019-exterior-front-view-new-gray-model-x.jpg');
background-size: cover;
}
<div class="blurred"></div>
Update (8-8-2022): This is now also fully supported in Firefox
I have added overflow, padding and even margin, but still the problem not solved. So i tried to give the image tag between div. Problem solved.
<div class="background-image">
<img src="http://www.hdpaperz.com/wallpaper/original/windows-8-wallpapers-2560x1600-2311_1.jpg" width="100%" height="100%"/>
</div>
css
.background-image {
background: no-repeat center center fixed;
background-size: cover;
display: block;
left: -5px;
top:-5px;
bottom:-5px;
position: fixed;
right: -5px;
z-index: 1;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
margin:-5px;
}
js fiddle
http://jsfiddle.net/2pgdttLh/
This worked for me:
Added two fixed images, one with z=-1, other with z=0, blurred the first one.
Use a SVG-Blur filter.
filter: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='a' x='0' y='0' width='1' height='1' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='4' result='b'/%3E%3CfeMorphology operator='dilate' radius='4'/%3E %3CfeMerge%3E%3CfeMergeNode/%3E%3CfeMergeNode in='b'/%3E%3C/feMerge%3E%3C/filter%3E %3C/svg%3E#a");
"stdDeviation" is your intensity.
source
I added a negative margin to the container: margin: -5px
Here's a function I settled on based on #Prime 's answer.
In order for it to work the image must be positioned inside a <div/> having the width and height of the image (explicitly set).
function addBlur(style, radius) {
return {
...style,
// https://caniuse.com/#feat=css-filters
filter: `blur(${radius}px)`,
// Works around the white edges bug.
// https://stackoverflow.com/questions/28870932/how-to-remove-white-border-from-blur-background-image
width: `calc(100% + ${2 * radius}px)`,
height: `calc(100% + ${2 * radius}px)`,
marginLeft: `-${radius}px`,
marginTop: `-${radius}px`
}
}
The blur adds transparency around the edges, so all you need to do is remove the alpha channel.
Here are a couple of examples of how to do this with SVG filters.
<filter id="omega"><feColorMatrix values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1"/></filter>
<filter id="omega"><feComponentTransfer><feFuncA type="linear" slope="10"/></feComponentTransfer></filter>
You can implement blur immediately in the SVG filter, or add a filter to remove transparency after the blur
filter: blur(50px) url(#omega);
or pure CSS
filter: blur(50px) url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"><filter id="a"><feComponentTransfer><feFuncA type="linear" slope="10"/></feComponentTransfer></filter>#a');
If the white borders are caused by the background color of the body, apply margin: 0; on body since margins are not 0 by default;
padding: 10px 10px;
add this in your css to remove the white blur border for bottom

Dotted background overlay effect in CSS

I'm trying to achieve the background effect on this website:
http://mountaintheme.com/themeforest/mountain/home.html
The background pictures seem to be covered in a dotted overlay sort of thing.
Is there a way to create this effect with CSS only?
A little bit late, but here is a solution that uses just CSS to create the dotted overlay using a pattern created with radial-gradient.
.image {
width: 800px;
height: 600px;
position: relative;
background: url('https://upload.wikimedia.org/wikipedia/commons/6/6e/Rathong_from_Zemathang2.jpg');
background-size: cover;
}
.image:after {
content: '';
display: block;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: rgba(127, 127, 127, 0.5);
background-image: radial-gradient(black 33%, transparent 33%);
background-size: 2px 2px;
}
<div class="image"></div>
Here is my way of doing this https://jsfiddle.net/soumyabg/wefLyrhp/
Very minimal and pure CSS solution. The catch is that the actual image is the background of <a> tag (with display:block), and <img> is the dot overlay (its size should be defined in the CSS).
HTML:
<div class="image-container">
<a class="dotm" href="#">
<img src="http://s14.directupload.net/images/111129/44ga9qid.png" alt="dotm" title="dotm" class="dotm-overlay">
</a>
</div>
CSS:
.dotm {
display: block;
background: url(https://media.giphy.com/media/SOoaHiWfwZyfu/giphy.gif) no-repeat; /* change with the image URL */
background-size: cover;
}
.dotm-overlay {
background: url(http://s14.directupload.net/images/111129/44ga9qid.png);
width: 100%;
height: 400px; /*height of the image*/
}
Output:
You can implement this using only css background properties:
background-image: radial-gradient(black 50%, transparent 50%);
background-size: 4px 4px;
Here's one way of doing it.
<body>
<div id="overlay">
image
</div>
<div id="page">
<div id="content">
....
Basically, you add a container outside your page container.
Add a fixed position for it, and add a pseudo element :after to it and give it a background image.
Assume you have an object with "bg" id, this css class will add small dotted background:
#bg {
background-image: radial-gradient(#000 10%, transparent 10%);
background-size: 15px 15px;
background-color: #EEE;
}
You can change dots color by replace black (#000) with any color, and background color by replacing #EEE.
To adjust dots size, play with 10% and 15px.