How Can One Create an Overlay in CSS

How can one create an overlay in css?

You can use position:absolute to position an overlay inside of your div and then stretch it in all directions like so:

CSS updated *

.overlay {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background-color:rgba(0, 0, 0, 0.85);
background: url(data:;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAABl0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuNUmK/OAAAAATSURBVBhXY2RgYNgHxGAAYuwDAA78AjwwRoQYAAAAAElFTkSuQmCC) repeat scroll transparent\9; /* ie fallback png background image */
z-index:9999;
color:white;
}

You just need to make sure that your parent div has the position:relative property added to it and a lower z-index.


Made a demo that should work in all browsers, including IE7+, for a commenter below.

Demo

Removed the opacity property from the css and instead used an rGBA color to give the background, and only the background, an opacity level. This way the content that the overlay carries will not be affected. Since IE does not support rGBA i used an IE hack instead to give it an base64 encoded PNG background image that fills the overlay div instead, this way we can evade IEs opacity issue where it applies the opacity to the children elements as well.

How to overlay image with color in CSS?

You should use rgba for overlaying your element with photos.rgba is a way to declare a color in CSS that includes alpha transparency support. you can use .row as an overlayer like this:

#header {
background: url(../img/bg.jpg) 0 0 no-repeat fixed;
height: 100%;
overflow: hidden;
color: #FFFFFF
}

.row{
background: rgba(39,62,84,0.82);
overflow: hidden;
height: 100%;
z-index: 2;
}

How can i add an overlay to an image in css or any other way

Here's one simple method, using a pseudo-element (::before) with a semi-transparent background (black with 50% opacity, defined by rgba) overlayed above an image.

.dark-img {  position: relative;  width: 300px;}
.dark-img img { display: block; width: 100%;}
.dark-img::before { content: ''; position: absolute; top: 0; left: 0; bottom: 0; right: 0; z-index: 1; background: rgba(0, 0, 0, .5);}
<div class="dark-img">  <img src="https://i.imgur.com/qLRD0OC.jpg" /></div>

How to add a color overlay to a background image?

I see 2 easy options:

  • multiple background with a translucent single gradient over image
  • huge inset shadow

gradient option:

    html {
min-height:100%;
background:linear-gradient(0deg, rgba(255, 0, 150, 0.3), rgba(255, 0, 150, 0.3)), url(https://picsum.photos/id/1043/800/600);
background-size:cover;
}

How to make in CSS an overlay over an image?

You can achieve this with this simple CSS/HTML:

.image-container {
position: relative;
width: 200px;
height: 300px;
}
.image-container .after {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
color: #FFF;
}
.image-container:hover .after {
display: block;
background: rgba(0, 0, 0, .6);
}

HTML

<div class="image-container">
<img src="http://lorempixel.com/300/200" />
<div class="after">This is some content</div>
</div>

Demo: http://jsfiddle.net/6Mt3Q/


UPD: Here is one nice final demo with some extra stylings.

.image-container {    position: relative;    display: inline-block;}.image-container img {display: block;}.image-container .after {    position: absolute;    top: 0;    left: 0;    width: 100%;    height: 100%;    display: none;    color: #FFF;}.image-container:hover .after {    display: block;    background: rgba(0, 0, 0, .6);}.image-container .after .content {    position: absolute;    bottom: 0;    font-family: Arial;    text-align: center;    width: 100%;    box-sizing: border-box;    padding: 5px;}.image-container .after .zoom {    color: #DDD;    font-size: 48px;    position: absolute;    top: 50%;    left: 50%;    margin: -30px 0 0 -19px;    height: 50px;    width: 45px;    cursor: pointer;}.image-container .after .zoom:hover {    color: #FFF;}
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"/>
<div class="image-container"> <img src="http://lorempixel.com/300/180" /> <div class="after"> <span class="content">This is some content. It can be long and span several lines.</span> <span class="zoom"> <i class="fa fa-search"></i> </span> </div></div>

How to make background overlay?

You can achieve it by using box-shadow as overlay white, and element will become a porthole like that:

.background {
width: 100%;
height: 300px;
background-position: center;
background-size: cover;
position: relative;
overflow: hidden;
}

.hole {
width: 120px;
height: 200px;
position: absolute;
top: 50px;
right: 100px;
border: 10px solid white;
border-radius: 80px;
box-shadow: 0px 0px 0px 99999px rgb(255 255 255 / 80%);
}
<section class="background" style="background-image: url('https://images.pexels.com/photos/62623/wing-plane-flying-airplane-62623.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260')">
<div class="hole"></div>
</section>

How to cover a div with another div as overlay

take the both div inside a root div.Then set the root div position:relative and overlay div absolute. fix the height and width. and apply display:bloCK on overlay div. If still does not work than apply z-index.

This should be like:
HTML:

<div class="parent">
<div id="area" class="area"></div>
<div class="area cover"></div>
</div>

CSS:

.parent{
position: relative;
height:200px;
width: 200px;
}
.cover{
position: absolute;
height: 100%;
width: 100%;
display: block;
z-index: 999;
}

Hopefully this will work for you.

How to overlay one div over another div

#container {  width: 100px;  height: 100px;  position: relative;}#navi,#infoi {  width: 100%;  height: 100%;  position: absolute;  top: 0;  left: 0;}#infoi {  z-index: 10;}
<div id="container">  <div id="navi">a</div>  <div id="infoi">    <img src="https://appharbor.com/assets/images/stackoverflow-logo.png" height="20" width="32" />b  </div></div>


Related Topics



Leave a reply



Submit