* {
padding: 0;
margin: 0;
}
html,
body {
height: 100%;
}
.body {
height: 100vh;
text-align: center;
}
.square {
width: 100vm;
height: 100vm;
/* For IE9 */
width: 100vmin;
height: 100vmin;
display: inline-block;
vertical-align: middle;
margin-top: calc((100vh - 100vmin) / 2);
background-image: url('https://ae01.alicdn.com/kf/HTB12ZJjMXXXXXa_aXXXq6xXFXXXE/3-Piece-Wall-font-b-Picture-b-font-Dreamy-font-b-Purple-b-font-font-b.jpg');
font-size: 0;
}
.square:before {
content: "";
height: 100%;
}
.square:before,
.content {
display: inline-block;
vertical-align: middle;
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Firefox < 16 */
@-moz-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Safari, Chrome and Opera > 12.1 */
@-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Internet Explorer */
@-ms-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Opera < 12.1 */
@-o-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.content {
-webkit-animation: fadein 1s;
/* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 1s;
/* Firefox < 16 */
-ms-animation: fadein 1s;
/* Internet Explorer */
-o-animation: fadein 1s;
/* Opera < 12.1 */
animation: fadein 1s;
}
#left-content {
background-size: cover;
width: 50vmin;
height: 100vmin;
float: left;
}
#right-content {
background-size: cover;
width: 50vmin;
height: 100vmin;
float: right;
}
#left-content:after {
background-size: cover;
width: 50vmin;
height: 100vmin;
float: left;
opacity: 0;
content: ' ';
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#right-content:after {
background-size: cover;
width: 50vmin;
height: 100vmin;
float: right;
opacity: 0;
content: ' ';
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#left-content:hover:after+.square {
background-image: url('https://ae01.alicdn.com/kf/HTB1EuKlLVXXXXcmXpXXq6xXFXXXd/E-HOME-Stretched-LED-Canvas-Print-Blue-Rose-Flash-Effect-LED-Flashing-font-b-Optical-b.jpg');
opacity: 1;
}
#right-content:hover:after {
background-image: url('https://ae01.alicdn.com/kf/HTB12hyVPVXXXXbEaXXXq6xXFXXX8/-font-b-Canvas-b-font-Painting-Printed-Pictures-Paints-Wall-Hanging-font-b-Canvas-b.jpg');
opacity: 1;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="body">
<div class="square">
<div class="content">
<a href="">
<div id="left-content"></div>
</a>
<a href="">
<div id="right-content"></div>
</a>
</div>
</div>
</div>
</body>
</html>
I would like to do the following.
DIV container contains two DIV (1 and 2). When mouse is over DIV 1, the background image of DIV CONTAINER change to image1. When mouse is over DIV 2, the background image of DIV CONTAINER change to image2.
I would like to try this with only CSS.