gpt4 book ai didi

html - 用 CSS 和 HTML 制作的六边形菜单

转载 作者:太空宇宙 更新时间:2023-11-04 09:08:44 24 4
gpt4 key购买 nike

我尝试制作一个六边形菜单,看起来像这样。但我遇到了一些麻烦。

  1. 保持响应。
  2. 让它们包含文本。
  3. 边界。

enter image description here

我已经编写了这段代码,但是当它包含文本或边框时效果不佳。

CSS

ol.even {
position: relative;
left: 5.45455rem;
}

ol.odd {
position: relative;
margin-bottom: -4.5%;
}

.hex {
position: relative;
margin: 1em auto;
width: 6rem;
height: 10.2rem;
background: #1e2530;
transform: rotate(-90deg);
display: inline-block;
list-style-type: none;
margin-right: 4.61538rem;
transition: all 150ms ease-in-out;
z-index: 2;
}

.hex:before, .hex:after {
position: absolute;
width: inherit;
height: inherit;
border-radius: inherit;
background: inherit;
content: '';
z-index: -1;
}

.hex:before {
transform: rotate(60deg);
}

.hex:after {
transform: rotate(-60deg);
}

.hex:hover {
background: #ea7432;
cursor: pointer;
}

HTML

<ol class="odd">
<li class='hex'></li>
<li class='hex'></li>
<li class='hex'></li>
<li class='hex'></li>
</ol>
<ol class="even">
<li class='hex'></li>
<li class='hex'></li>
<li class='hex'></li>
</ol>

结果是这样的。但它不能包含文本或边框 enter image description here

要怎么做才能像第一张图片上的六边形菜单一样工作?

最佳答案

将六边形内容放在新元素中并应用以下 CSS 将其正确放置:

HTML

<ol class="odd">
<li class="hex">
<div class="hex-content">Welcome</div>
</li>
<li class="hex"></li>
<li class="hex"></li>
<li class="hex"></li>
</ol>

CSS

 .hex .hex-content {
position: absolute;
top: 50%;
left: 50%;

transform: translate(-50%, -50%) rotate(90deg);

color: white;
}

对于边框,您可以使用实心细外阴影和深色粗边框来获得此效果。 Here你可以找到一个很好的起点。

关于html - 用 CSS 和 HTML 制作的六边形菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42280954/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com