4

我正在尝试制作六边形网格。对于一个时髦的效果,我使用了 css 变换效果。在 FireFox 中,这似乎功能正确,但在 Google Chrome 中,顶部 div 似乎没有给出预期的悬停效果。这是我使用的代码:

<html>
<head>
<style>
body{
    margin:0;
}
.board{
    width: 550px;
    height: 300px;
    margin: 20px auto;
    -webkit-transform: perspective(700px) rotateX(65deg);
    -moz-transform: perspective(700px) rotateX(65deg);
    -ms-transform: perspective(700px) rotateX(65deg);
    -o-transform: perspective(700px) rotateX(65deg);
    transform: perspective(700px) rotateX(65deg);
    padding:10;
}
.hex-row {
    clear: left;
}
.hex-row.even {
    margin-left: 53px;
}
.hex:hover{
    background: #446;
}
.hex:hover:before{
    border-bottom: 30px solid #446;
}
.hex:hover:after{
    border-top: 30px solid #446;
}

.hex:before {
    content: " ";
    width: 0; height: 0;
    border-bottom: 30px solid #6C6;
    border-left: 52px solid transparent;
    border-right: 52px solid transparent;
    position: absolute;
    top: -30px;
}
.hex {
    width: 104px;
    height: 60px;
    background-color: #6C6;
    position: relative;
    float:left;
    margin-top: 32px;
    margin-left: 3px;
    margin-bottom: 3px;
}
.hex:after {
    content: " ";
    width: 0;
    position: absolute;
    bottom: -30px;
    border-top: 30px solid #6C6;
    border-left: 52px solid transparent;
    border-right: 52px solid transparent;
}
.hex.disabled{
    background-color: #888;
}
.hex.disabled:before {
    border-bottom: 30px solid #888;
}
.hex.disabled:after {
    border-top: 30px solid #888;
}
</style>
</head>
<body>
<div class="board">
<div class="hex-row">
<div class="hex disabled"></div>
<div class="hex disabled"></div>
<div class="hex"></div>
<div class="hex disabled"></div>
<div class="hex disabled"></div>
</div>
<div class="hex-row even">
<div class="hex"></div>
<div class="hex"></div>
<div class="hex"></div>
<div class="hex"></div>
</div>
<div class="hex-row">
<div class="hex disabled"></div>
<div class="hex"></div>
<div class="hex"></div>
<div class="hex"></div>
<div class="hex disabled"></div>
</div>
<div class="hex-row even">
<div class="hex"></div>
<div class="hex"></div>
<div class="hex"></div>
<div class="hex"></div>
</div>
<div class="hex-row">
<div class="hex disabled"></div>
<div class="hex disabled"></div>
<div class="hex"></div>
<div class="hex disabled"></div>
<div class="hex disabled"></div>
</div>
</div>
</body>
</html>

为了快速尝试,您可以使用以下链接:http: //jsfiddle.net/a55eF/2/并单击“运行”按钮。您将在右下角看到结果。

有没有人有关于修复悬停的建议?提前致谢!

4

2 回答 2

2

身体正在阻止悬停事件,这就是我在 firefox 和 google chrome 之间看到的区别。添加高度时:0px;对于 body 元素,它确实会正确触发悬停事件。

于 2013-03-11T18:24:29.473 回答
1

我将其更改height为 10px 并将旋转角度更改为 75 度:

http://jsfiddle.net/a55eF/5/

似乎您想弄乱这些参数,特别是高度,以获得所需的效果。似乎高度越低,您可以悬停的顶行越多。

于 2013-03-11T18:19:41.230 回答