目标:
我正在为朋友的网站创建一个带有3D悬停效果的图形菜单。有一系列矩形。当鼠标悬停在其中一个上时,它将向上和向左移动,留下一个更暗的版本以显示它正在向外滑动。(屏幕截图中的红色圆圈只是为了显示问题区域。)
我的实现:
我使用一个无序列表,结构为<li><a><span>
。我目前已经成功实现了当鼠标悬停时正确移动,留下阴影。
代码:
(下面是JSFiddle)
HTML:
<section>
<li class="tall" id="logos"><a class="dark" href=""><span>Logos</span></a></li>
<li class="wide" id="illustrations"><a class="dark" href=""><span>Illustrations</span></a></li>
<li class="wide" id="drawings"><a href=""><span>Drawings</span></a></li>
<li class="small" id="web"><a href=""><span>Web</span></a></li>
<li class="small narrow" id="print"><a href=""><span>Print</span></a></li>
<li class="small" id="other"><a class="dark" href=""><span>Other</span></a></li>
</section>
CSS:
section { //Wrap
height:200px;
width:600px;
}
li {
list-style:none;
display:block;
float:left;
height:47%;
margin-bottom:2%;
}
a {
outline:0;
height:100%;
width:100%;
display:block;
color:black;
text-decoration:none;
position:relative;
top:0;
left:0;
box-shadow:0px 0px 0px 0px rgb(0,0,0);
transition: all 100ms ease-in;
background-color:inherit;
}
a:hover, a:focus {
top:-4px;
left:-4px;
box-shadow:4px 4px 0px 0px rgba(0,0,0,0.2);
}
span {
display:block;
position:absolute;
top:50%;
margin-top:-15px;
width:100%;
text-align:center;
font-family:Calibri;
font-size:22px;
font-weight:100;
}
//Sizes
.tall {
height:100%;
width:32%;
}
.wide {
width:32%;
margin-left:2%;
}
.small {
margin-left:2%;
width:21%;
}
.small.narrow {
width:20%;
}
.dark {
color:white;
}
//Colors
#logos {
background-color:rgb(242,25,44);
}
#illustrations {
background-color:rgb(41,90,95);
}
#drawings {
background-color:rgb(139,181,143);
}
#web {
background-color:rgb(187,222,189);
}
#print {
background-color:rgb(239,243,210);
}
#other {
background-color:rgb(242,25,44);
}
截图:
Fiddle:
我需要什么:
我需要找出如何让角落看起来是斜的。如果你注意到两张图片之间的区别,我的当前版本没有将它们连接起来。这可行吗?谢谢帮忙!
编辑:
我已经得到了两种不同的用颜色创建三角形的方法,但都需要一些调整才能得到我想要的效果。我不确定最终哪种方法会更简单,并且在动画时看起来更好。我将花一些时间来尝试它们,并回报我最终使用的是哪一个。感谢所有回答的人。(如果您有比已提出的更好的想法,请随意添加另一个答案。)
编辑 2:
使用web-tiki的方法,我在这里完全解决了它:http://jsfiddle.net/LhkEp/23/ 我认为这是最好的方法,因为没有故障,并且即使您减慢动画速度,一切都看起来完美。此外,通过更改使用包装的所有选择,如果您只是悬停在阴影上方,就不会来回移动。
inherit
,但那会显示白色。 - KeldericcurrentColor
,虽然我不确定浏览器的支持情况有多好 http://css-tricks.com/currentcolor/ - web-tikia
和li
的before和after。http://jsfiddle.net/LhkEp/19/现在我遇到的唯一问题是,如果你在变暗的部分悬停,会触发`li:hover`而不是`a:hover`,导致一个小故障。 - Kelderic