Just use the properties :before
or :after
, in case, :after
would be better for example, your code would look like this:
CSS
span{
position:relative;
}
div{
width: 640px;
height: 640px;
opacity: 1;
position: absolute;
}
div:after{
content:'';
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
background-color:rgba(0,0,0,.6);
}
div img{
width:100%;
}
HTML
<span>
<div>
<img src="https://scontent.cdninstagram.com/t51.2885-15/e15/11909170_999395153465997_38853384_n.jpg?ig_cache_key=MTA1NTI1MTUxNDA0OTkxNDkyMg%3D%3D.2"alt="">
</div>
</span>
Now, to explain it better, the :before
and :after
properties are used so that we can control a single element as if they were layers of it, before and after :after
was set to absolute so that we can use the According to top,left,right e bottom
, span
must be set to relative, because as you know, position absolute
responds to the first parent that is relativo
.
So to set the :before/:after
property we need to say, what content, hence the content:'';
to show that the content is empty and the property is presented to the end user correctly, so I give background-color
in after
and I already set opacidade
together with rgba(0~255,0~255,0~255,0~1)
.
It is as if you created in photoshop a layer
above your element, and gave it properties common to an element