1<style>
2.container {
3 position: relative;
4 width: 50%;
5}
6
7.image {
8 display: block;
9 width: 100%;
10 height: auto;
11}
12
13.overlay {
14 position: absolute;
15 top: 0;
16 bottom: 0;
17 left: 0;
18 right: 0;
19 height: 100%;
20 width: 100%;
21 opacity: 0;
22 transition: .5s ease;
23 background-color: #008CBA;
24}
25
26.container:hover .overlay {
27 opacity: 1;
28}
29
30.text {
31 color: white;
32 font-size: 20px;
33 position: absolute;
34 top: 50%;
35 left: 50%;
36 -webkit-transform: translate(-50%, -50%);
37 -ms-transform: translate(-50%, -50%);
38 transform: translate(-50%, -50%);
39 text-align: center;
40}
41</style>
42</head>
43<body>
44
45<h2>Fade in Overlay</h2>
46<p>Hover over the image to see the effect.</p>
47
48<div class="container">
49 <img src="Example.png" alt="Example" class="image">
50 <div class="overlay">
51 <div class="text">Hello World</div>
52 </div>
53</div>
54
55</body>