【发布时间】:2017-09-29 23:23:37
【问题描述】:
我的基于 CSS 的页面存在问题。 我想更改鼠标悬停在两个 div 上的背景图像,并在单击时指向另一个页面。 我有 3 个问题:
- 当屏幕为纵向分辨率而不是横向分辨率时,背景的变化可以正常工作。
- 我想在背景变化时制作一个淡入淡出动画,但我不知道怎么做。
- 我需要 div1 和 div2 作为链接,这样不仅背景会发生变化,如果用户单击它还指向另一个页面。我无法在不阻止 flex 显示的情况下添加 div。
谢谢!
* {
padding: 0;
margin: 0;
}
html,
body {
height: 100%;
text-align: center;
}
@media screen and (orientation:landscape) {
.container {
position: absolute;
display: flex;
width: 75vmin;
height: 100vmin;
top: 50%;
left: 50%;
transform: translate3d(-50%, -50%, 0);
}
.div1,
.div2 {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
width: 32.5vmin;
height: 100vmin;
background-color: #ddd;
}
}
@media screen and (orientation:portrait) {
.container {
position: absolute;
display: flex;
width: 100vmin;
height: 133vmin;
top: 50%;
left: 50%;
transform: translate3d(-50%, -50%, 0);
}
.div1,
.div2 {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
width: 50vmin;
height: 133vmin;
background-color: hsla(0, 0%, 0%, 0.1);
}
}
.background1,
.background2 {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: none;
z-index: -1;
}
.background1 {
background: url("http://i.imgur.com/zFYHM67.jpg");
background-repeat: no-repeat;
background-size: cover;
}
.background2 {
background: url("http://i.imgur.com/nYKEFNF.jpg");
background-repeat: no-repeat;
background-size: cover;
}
.div1:hover~.background1 {
display: flex;
}
.div2:hover~.background2 {
display: flex;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="div1">Div 1</div>
<div class="background1"></div>
<div class="div2">Div 2</div>
<div class="background2"></div>
</div>
</body>
</html>
【问题讨论】:
标签: css flexbox css-transitions