Cách tạo menu 6 cạnh tuyệt đêp ! lạ và ý tưởng ! thích hợp bạn nào thích dùng cái mới trong thiết kế web ! Create Beautiful Hexagon Shapes With Pure CSS3
In this tutorial, we are going to make hexagon shapes that support HTML content and also background image with just CSS3. CSS3 has been an amazing revision in creating more advanced styling. Don't believe me? Check this awesome graphic coded purely with CSS.
With CSS Transform, we can easily skew, rotate and other manipulations on DOM element. We are going to use CSS3 rotate and masking to achieve what we want. This tutorial will be slightly complicated in CSS part, and I have tried my best to explain it with illustrations. Alright, let's get started.
HTML
This hexagon can have two different styles. You can either put text content in it or just pure image. The HTML markup is quite similar and they also share the same CSS.
Referring to the HTML markup below, there are two div called .corner-1
and corner-2
, we will rotate these two divs to 60 degree to create the shape we want.
class="hex hex-3">
-
class="inner">
- CONTACT US
-
/>
- We Open Everyday
-
- href="#">
-
class="corner-1">
-
class="corner-2">
class="hex" style="background-image: url(images/2.jpg);">
- href="#">
-
class="corner-1">
-
class="corner-2">
CSS
Alright, it will be a little bit complicated in CSS section. A hexagon has six edges and each angle is 60 degree. We are going to build a hexagon with 3 rectangles. Referring to the picture below, in step 1 to 3, we are placing 2 rectangles on top of the main one and rotate them 60 degree. That's how a hexagon is made.
For the background image, there is more work to make it display correctly. Because we have rotated both corners, the background image is rotated as well. Therefore, to rectify this, we will be using :before
to duplicate its content, rotate it back, make it a square, and mask it with overflow:hidden
.
Here I have another illustration to let you see it a little bit more clearly.
Conclusion
This hexagon shape tutorial is pretty straight forward. It took me a while to figure it out and along the process of experiementing, I did pick up a few tricks such as CSS transform and masking. I hope you enjoy this, if you have any questions, drop us a comment. If you liked this, please share it via social media. Thanks :)