Skip to content

Instantly share code, notes, and snippets.

@gunnarbittersmann
Last active December 13, 2022 09:27
Show Gist options
  • Save gunnarbittersmann/791f20a828c15bec0926 to your computer and use it in GitHub Desktop.
Save gunnarbittersmann/791f20a828c15bec0926 to your computer and use it in GitHub Desktop.
hexagon clip-path
/**
* hexagon clip-path
*/
div
{
width: 400px;
height: 346px; /* ½√3 × width */
position: relative;
overflow: hidden;
-webkit-clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
-moz-clip-path: url(#hexagon);
clip-path: url(#hexagon);
}
img
{
position: absolute;
left: -270px;
top: -210px;
}
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/1/17/Vitruvian.jpg" alt="Vitruvian Man by Leonardo da Vinci"/>
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 346">
<clipPath id="hexagon">
<polygon points="100 0, 300 0, 400 173, 300 346, 100 346, 0 173"/>
</clipPath>
</svg>
// alert('Hello world!');
{"view":"split-vertical","fontsize":"100","seethrough":"","prefixfree":"","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment