我正在尝试创建两个类似的长六边形,如下图所示:
主要特点应该包括:
- 可以添加渐变背景
- 可以添加渐变边框
- 文本可以是单行或双行
- 响应式布局(Bootstrap网格)(最好有) - 角落的角度应始终相同。
根据仅使用一个元素创建长六边形形状按钮,到目前为止,最好的解决方案如下:https://jsfiddle.net/veuc78af/:
/*hexagons*/
.hexagon {
box-sizing: border-box;
position: relative;
display: inline-block;
min-width: 200px;
height: 80px;
margin: 40px auto;
color: #fd0;
text-align: center;
text-decoration: none;
line-height: 80px;
}
.hexagon:before, .hexagon:after {
position: absolute;
content:'';
width: 100%;
left: 0px;
height: 34px;
z-index: -1;
}
.hexagon:before {
transform: perspective(15px) rotateX(3deg);
}
.hexagon:after {
top: 40px;
transform: perspective(15px) rotateX(-3deg);
}
/* hexagon Border Style */
.hexagon.border:before, .hexagon.border:after {
border: 4px solid #fd0;
}
.hexagon.border:before {
border-bottom: none;
/* to prevent the border-line showing up in the middle of the shape */
}
.hexagon.border:after {
border-top: none;
/* to prevent the border-line showing up in the middle of the shape */
}
/* hexagon hover styles */
.hexagon.border:hover:before, .hexagon.border:hover:after {
background: #fd0;
}
.hexagon.border:hover {
color: #fff;
}
这个解决方案的主要问题是无法创建渐变背景。所以在我的情况下这行不通。
有没有可能做到呢?
这个项目的主要平台是iPad2上的Safari。
clip-path
,但浏览器支持很差(IE根本不支持它,FF需要SVG作为路径提供)。 - Harry