There is a way to do this without having to add or alter the html and it is taking advantage of pseudoselectives :before o :after
, although they already gave you a solution (which is perfectly valid), I suggest you check this other , which can also be interesting to know. :)
Look:
.fondo_banner {
margin: 0 auto 1em;
position: relative;
height: 240px;
overflow: hidden;
}
.fondo_banner::before{ /*Esta es la imagen de fondo*/
content: '';
background-image: url(https://www.walldevil.com/wallpapers/a49/desktop-wallpaper-nepal-background-wallpapers.jpg);
background-repeat: no-repeat;
background-position: 100%;
background-size: cover;
display: block;
z-index: 1;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.fondo_banner:hover::before{
filter: blur(10px);
transition: all linear .5s;
}
.fondo_banner::after { /*esta es la capa overlay*/
content: '';
background-color: rgba(69, 90, 100, 0.6);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
display: block;
}
#pUsuario_avatar {
background-image: url(http://pia.az/photos/gffbff.jpg);
position: relative;
width: 85px;
height: 85px;
background-size: cover;
background-position: top center;
border-radius: 50%;
margin: 15px auto;
cursor: pointer;
z-index: 3;
}
<div class="fondo_banner">
<div id="pUsuario_avatar">
</div>
</div>
The first thing you must do to achieve this, is to create the pseudo-element selector, which what you do in a few words is to generate another html element, without modifying the html (imagine the possibilities hehe), this is how we create it:
.fondo_banner::before{}
Of course, nothing will be seen unless you put what kind of content is going to have inside, in this case it will not have anything, like this:
.fondo_banner::before{
content: '';
}
Now even though it's going to be empty, it's going to have a background so we pass all the background image data to this selector.
.fondo_banner::before{
content: '';
background-image: url(https://www.walldevil.com/wallpapers/a49/desktop-wallpaper-nepal-background-wallpapers.jpg);
background-repeat: no-repeat;
background-position: 100%;
}
Now you have to tell it to occupy all the parent element (which must necessarily have a position: relative
, which in your case it already has), as in the beginning this element is of type inline
will not take the width and the high, unassigned first that will behave as a block or ( block in line or if you want flex , table , etc), once we do this we can add an absolute position and a z-index, for the control of the layers.
.fondo_banner::before{
content: '';
background-image: url(https://www.walldevil.com/wallpapers/a49/desktop-wallpaper-nepal-background-wallpapers.jpg);
background-repeat: no-repeat;
background-position: 100%;
background-size: cover;
display: block;
z-index: 1;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
And so that when you pass the hover, this is added the blur you must compose the selector like this:
.fondo_banner:hover::before{
filter: blur(10px);
}
In fact, this technique is so useful, that you could even do without the other element in the html that made overlay layer , in fact in the example I did it.
The only downside (if we can call this technique an inconvenience) is that it only has a creation maximum (at the moment) of up to 2 elements ( after y before
).