【发布时间】:2018-10-17 02:06:36
【问题描述】:
我正在尝试制作一种稍后将用于导航的维恩图。
我用 CSS 形状创建了三个相交的椭圆体。每个椭圆体,以及它们的两个交点,稍后将成为不同的链接。此外,当您将鼠标悬停在它们上方时,它们应该按照transform: scale(1.3) 弹出。
我的问题是我正在使用与:after 部分透明的椭圆体来创建交叉点,当将鼠标悬停在它们上方时会产生问题,因为当悬停在部分透明的椭圆体上的任何位置时会触发:hover 条件和不仅仅是:after part。这意味着非相交区域不能悬停,因为它们被另一个不可见的椭球阻挡。
我认为这个例子会更清楚。
代码如下:
CSS:
.venn-container{position: relative; left: 0;}
.cat_one{
width: 400px;
height: 200px;
background: red;
border-radius: 200px / 100px;
position: absolute;
float: left;
opacity: 0.5;
}
.cat_two{
width: 400px;
height: 200px;
background: green;
border-radius: 200px / 100px;
position: absolute;
float: left;
left: 240px;
opacity: 0.5;
}
.cat_three{
width: 400px;
height: 200px;
background: blue;
border-radius: 200px / 100px;
position: absolute;
float: left;
left: 480px;
opacity: 0.5;
}
.int1{
background: transparent;
width: 400px;
height: 200px;
border-radius: 200px / 100px;
position: relative;
opacity: 0.5;
overflow: hidden;
float: left;
}
.int1:after{
background: black;
position: absolute;
content: '';
border-radius: 200px / 100px;
width: 400px;
height: 200px;
left: 240px;
}
.int1:hover{
transform: scale(1.3);
left: -35px;
}
.int2{
background: transparent;
width: 400px;
height: 200px;
border-radius: 200px / 100px;
position: relative;
opacity: 0.5;
overflow: hidden;
float: left;
left: 80px;
}
.int2:after{
background: black;
position: absolute;
content: '';
border-radius: 200px / 100px;
width: 400px;
height: 200px;
left: -240px;
}
.int2:hover{
transform: scale(1.3);
left: 115px;
}
HTML:
<div class="venn-container">
<div class="cat_one"></div>
<div class="cat_two"></div>
<div class="cat_three"></div>
<div class="int1"></div>
<div class="int2"></div>
</div>
这是一个小提琴:https://jsfiddle.net/y3Lvmuqg/2/
我希望:hover 只在交叉路口触发,然后让cat_one 和cat_two 在交叉路口外悬停。
我不知道是否有最好的方法,我愿意接受建议。
【问题讨论】:
-
像这样尝试
int1:hover::after并给transitionti int1 -
过渡到 int1 是什么意思?
-
过渡属性。
-
你的意思是过渡:1s; ?
-
是的
transition: all 2s linear;
标签: html css hover css-shapes