gpt4 book ai didi

javascript - 如何制作内联六边形画廊

转载 作者:行者123 更新时间:2023-12-05 03:24:05 28 4
gpt4 key购买 nike

  .hexagon-gallery {
margin: auto;
margin-top: 50px;
max-width: 1000px;
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-auto-rows: 200px;
padding-bottom: 50px;
}

.hex {
display: flex;
position: relative;
width: 240px;
height: 265px;
background-color: #424242;
-webkit-clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.hex:first-child {
grid-row-start: 1;
grid-column: 3 / span 2;
}

.hex:nth-child(2) {
grid-row-start: 1;
grid-column: 4 / span 2;
}

.hex:nth-child(3) {
grid-row-start: 1;
grid-column: 6 / span 2;
}
       <section class="hexagon-gallery">
<div class="hex"><img src="https://images.pexels.com/photos/1421264/pexels-photo-1421264.jpeg?cs=srgb&dl=aerial-aerial-photo-aerial-photography-1421264.jpg&fm=jpg" alt="some"></div>
<div class="hex"></div>
<div class="hex"></div>
</section>

enter image description here

我试图瞄准类似形状的东西。六边形拉伸(stretch)拼写错误形状,如果有任何其他更简单的方法可以做到这一点,我想知道。也许两边形状的矩形都可以,我不确定。

最佳答案

那行得通吗?我整理了一些代码以删除无关的 CSS 属性。

主要部分是:

  • clip-path: polygon(85% 0%, 100% 50%, 85% 100%, 15% 100%, 0% 50%, 15% 0%); 得到正确的形状。
  • grid-auto-flow: column;grid-auto-columns: 168px;(这是你的 .hex 宽度 -30 %,因为形状在每边切割 15%)以正确对齐元素。`
  • z-index 应按递减顺序排列,以便每个元素始终覆盖下一个元素。如果你删除 z-index 你会产生相反的效果(每个元素被下一个元素覆盖),默认情况下在 HTML 中,位于其兄弟组底部的元素出现在“上方” "它上面的元素。
  • 为了整洁 grid-auto-rows: 0px; 替换每个元素上的 grid-row-start: 1;

.hexagon-gallery {
display: grid;
grid-auto-rows: 0px;
grid-auto-columns: 168px;
grid-auto-flow: column;
}

.hex {
display: flex;
width: 240px;
height: 265px;
clip-path: polygon(85% 0%, 100% 50%, 85% 100%, 15% 100%, 0% 50%, 15% 0%);
}

.hex:first-child {
background: red;
z-index: 1000;
}

.hex:nth-child(2) {
background: green;
z-index: 900;
}

.hex:nth-child(3) {
background: blue;
z-index: 800;
}
<section class="hexagon-gallery">
<div class="hex"><img src="https://images.pexels.com/photos/1421264/pexels-photo-1421264.jpeg?cs=srgb&dl=aerial-aerial-photo-aerial-photography-1421264.jpg&fm=jpg" alt="some"></div>
<div class="hex"></div>
<div class="hex"></div>
</section>

要调整形状,请修改 85%15%(如果您想保持对称形状,它们的总和应始终为 100)。
例如改用 75% 和 25% 会使 Angular 变大。
不要忘记将 grid-auto-columns 值更改为 width * (25*2)%,因此在本例中为 120px保持每个元素之间的正确间距。
使用这些参数的示例: enter image description here

关于javascript - 如何制作内联六边形画廊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72352447/

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