我有一個由CSS創建的六角形。我試圖在六角形內獲得一個頁眉,段落和按鈕,但所有這些元素都隱藏在六邊形格式化之前和之後。這裏是代碼的鏈接:https://jsfiddle.net/o8a3pm3h/6/。 任何有關如何將元素放置在六角形表面的建議,我們感激不盡。CSS六角形與內部元素
#hex3 {
width: 200px;
height: 200px;
}
#color3 {
background-color: #CED7DC;
}
.hexagon-wrapper {
text-align: center;
margin: 20px;
position: relative;
display: inline-block;
}
.hexagon {
height: 100%;
width: calc(100% * 0.57735);
display: inline-block;
z-index: 1;
}
.hexagon:before {
position: absolute;
top: 0;
right: calc((100%/2) - ((100% * 0.57735)/2));
background-color: inherit;
height: inherit;
width: inherit;
content: '';
transform: rotateZ(60deg);
}
.hexagon:after {
position: absolute;
top: 0;
right: calc((100%/2) - ((100% * 0.57735)/2));
background-color: inherit;
height: inherit;
width: inherit;
content: '';
transform: rotateZ(-60deg);
}
<!--Please maintain the styling here because its on top of an image-->
<div id="hex3" class="hexagon-wrapper" style="position:absolute; top:80px; right:400px;">
<div id="color3" class="hexagon">
<h4>TEST</h4>
<p>TESTTTTTTTTTT</p>
<button type="button" class="btn btn-secondary" id="grid-row-btn-2" onclick="location.href='/#/'">
DISCOVER MORE <span class="glyphicon glyphicon-chevron-right"></span>
</button>
</div>
</div>
**另外,我知道,行內CSS是不好的做法,但它只是這個演示。
https://jsfiddle.net/o8a3pm3h/7/'.hexagon:之前,.hexagon:{ 的z-index:-1;}'後工作正常,太;) –