{"id":3121,"date":"2019-03-21T07:38:00","date_gmt":"2019-03-21T07:38:00","guid":{"rendered":"https:\/\/rengga.dev\/blog\/?p=3121"},"modified":"2023-02-28T09:10:33","modified_gmt":"2023-02-28T09:10:33","slug":"css-tutorial-css-grid-of-hexagons","status":"publish","type":"post","link":"https:\/\/rengga.dev\/blog\/css-tutorial-css-grid-of-hexagons\/","title":{"rendered":"CSS Tutorial &#8211; CSS Grid of Hexagons"},"content":{"rendered":"<p><span style=\"color: #ef3207;\"><a style=\"color: #ef3207;\" href=\"https:\/\/rengga.dev\/\" target=\"_blank\" rel=\"noopener\"><strong>Rengga Dev<\/strong><\/a> <\/span>&#8211; This time, I want to dive into another type of grid, one that works with shapes.<\/p>\n<p>Like, what if the images aren\u2019t perfectly square but instead are shaped like hexagons or rhombuses? Spoiler alert: we can do it. In fact, we\u2019re going to combine CSS Grid techniques we\u2019ve looked at and drop in some CSS\u00a0<code>clip-path<\/code>\u00a0and\u00a0<code>mask<\/code>\u00a0magic to create fancy grids of images for just about any shape you can imagine!<br \/>\n<iframe style=\"width: 100%;\" title=\"Untitled\" src=\"https:\/\/codepen.io\/renggagumilar\/embed\/abYXrLE?default-tab=result&amp;theme-id=dark\" height=\"500\" frameborder=\"no\" scrolling=\"no\" allowfullscreen=\"allowfullscreen\"><br \/>\nSee the Pen <a href=\"https:\/\/codepen.io\/renggagumilar\/pen\/abYXrLE\"><br \/>\nUntitled<\/a> by Rengga Gumilar (<a href=\"https:\/\/codepen.io\/renggagumilar\">@renggagumilar<\/a>)<br \/>\non <a href=\"https:\/\/codepen.io\">CodePen<\/a>.<br \/>\n<\/iframe><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">&lt;div class=\"gallery\"&gt;\r\n  &lt;img src=\"https:\/\/picsum.photos\/id\/1040\/300\/300\" alt=\"a house on a mountain\"&gt;\r\n  &lt;img src=\"https:\/\/picsum.photos\/id\/106\/300\/300\" alt=\"sime pink flowers\"&gt;\r\n  &lt;img src=\"https:\/\/picsum.photos\/id\/136\/300\/300\" alt=\"big rocks with some trees\"&gt;\r\n  &lt;img src=\"https:\/\/picsum.photos\/id\/1039\/300\/300\" alt=\"a waterfall, a lot of tree and a great view from the sky\"&gt;\r\n  &lt;img src=\"https:\/\/picsum.photos\/id\/110\/300\/300\" alt=\"a cool landscape\"&gt;\r\n  &lt;img src=\"https:\/\/picsum.photos\/id\/1047\/300\/300\" alt=\"inside a town between two big buildings\"&gt;\r\n  &lt;img src=\"https:\/\/picsum.photos\/id\/1057\/300\/300\" alt=\"a great view of the sea above the mountain\"&gt;\r\n&lt;\/div&gt;<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\">.gallery {\r\n  --s: 130px; \/* control the size *\/\r\n  --g: 10px;  \/* control the gap *\/\r\n  display: grid;\r\n  margin: calc(var(--s) + var(--g));\r\n}\r\n\r\n.gallery &gt; img {\r\n  grid-area: 1\/1;\r\n  width: var(--s);\r\n  aspect-ratio: 0.866;\r\n  object-fit: cover;\r\n  clip-path: polygon(0% 25%,0% 75%,50% 100%,100% 75%,100% 25%,50% 0);\r\n  transform: translate(var(--_x,0),var(--_y,0)) scale(var(--_t,1));\r\n  cursor: pointer;\r\n  filter: grayscale(80%);\r\n  transition: .2s linear;\r\n}\r\n.gallery &gt; img:hover {\r\n  filter: grayscale(0);\r\n  z-index: 1;\r\n  --_t: 1.2;\r\n}\r\n\r\n.gallery &gt; img:nth-child(1) {--_x: calc(-100% - var(--g))}\r\n.gallery &gt; img:nth-child(7) {--_x: calc( 100% + var(--g))}\r\n.gallery &gt; img:nth-child(3),\r\n.gallery &gt; img:nth-child(5) {--_y: calc(-75% - .87*var(--g))}\r\n.gallery &gt; img:nth-child(4),\r\n.gallery &gt; img:nth-child(6) {--_y: calc( 75% + .87*var(--g))}\r\n.gallery &gt; img:nth-child(3),\r\n.gallery &gt; img:nth-child(4) {--_x: calc(-50% - .5*var(--g))}\r\n.gallery &gt; img:nth-child(5), \r\n.gallery &gt; img:nth-child(6) {--_x: calc( 50% + .5*var(--g))}\r\n\r\n\r\nbody {\r\n  margin: 0;\r\n  min-height: 100vh;\r\n  display: grid;\r\n  place-content: center;\r\n  background: #aabbfb;\r\n}<\/pre>\n<p>If you check the code and compare it with the previous one you will notice that I have simply swapped the values inside\u00a0<code>clip-path<\/code>\u00a0and I switched between\u00a0<code>--x<\/code>\u00a0and\u00a0<code>--y<\/code>. That\u2019s all!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rengga Dev &#8211; This time, I want to dive into another type <a class=\"read-more\" href=\"https:\/\/rengga.dev\/blog\/css-tutorial-css-grid-of-hexagons\/\" title=\"CSS Tutorial &#8211; CSS Grid of Hexagons\" itemprop=\"url\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":3852,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[268,298,197,103,227],"newstopic":[],"class_list":{"0":"post-3121","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-html-css","8":"tag-css-grid","9":"tag-css-grid-of-hexagons","10":"tag-css-tutorial","11":"tag-web-design","12":"tag-web-designer"},"_links":{"self":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/comments?post=3121"}],"version-history":[{"count":1,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3121\/revisions"}],"predecessor-version":[{"id":3123,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3121\/revisions\/3123"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media\/3852"}],"wp:attachment":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media?parent=3121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/categories?post=3121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/tags?post=3121"},{"taxonomy":"newstopic","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/newstopic?post=3121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}