


CSS3 implements hexagonal Div image display effect_html/css_WEB-ITnose
Rendering:
Implementation principle:
The main css styles for this effect are:
1.>transform: rotate(120deg); Image rotation
2.>overflow:hidden; beyond hiding
3.>visibility: hidden; is also hidden, and display:none; is similar, but the difference is that although it is hidden, it will still occupy a position in the web page
We need to use 3 layers of divs to rotate to get this effect ( ps: The sizes of the three layers of divs are the same).
The outermost div (boxF) is rotated 120 degrees. The second layer (boxS) is rotated -60 degrees, and the third layer (boxT) is rotated -60 degrees again, and is now back to normal. Our picture is placed in the div background of the third layer. Because there is nothing in the first two layers of divs, they are purely used to rotate to get a hexagonal shape, so set visibility: hidden for the divs on the 1st and 2nd layers; and the div on the third layer is for pictures and needs to be displayed, so set visibility: visible; (ps: If you do not set visibility: visible; on the third layer div, it will inherit the visibility: hidden; of the second layer div (boxS) by default). There will definitely be excess parts after rotation, so set overflow:hidden;
for all three divs. After rotation and hiding the excess parts, we can get the 6-sided shape we want. Another thing to note is that the width and height of the div should not be equal, otherwise the result will not be a hexagon.
in the effect picture above. I also placed a div (overlay) in the third layer (boxT). This div is used for masking. When the mouse moves over the 6-sided shape, there will be a masking effect. There is an a tag inside the div (overlay) with a number inside. Click the a tag to pop up the layer and display the large image (ps: This js effect has not been written yet)
As given below DEMO code of the above rendering:
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CSS3 实现六边形图片展示效果</title> <style type="text/css"> body, div, img, ul, li { margin: 0; padding: 0; } body { font-size: 12px; background-color: #DDD; min-width: 1200px; } ul, ul li { list-style: none; } .clear { clear: both; } .box { position: relative; width: 630px; margin: 100px auto; } .lineF, .lineS { position: absolute; visibility: hidden; } .lineS { top: 182px; left: 105px; } .boxF, .boxS, .boxT, .overlay { width: 200px; height: 250px; overflow: hidden; } .boxF, .boxS { visibility: hidden; } .boxF { transform: rotate(120deg); float: left; margin-left: 10px; -ms-transform: rotate(120deg); -moz-transform: rotate(120deg); -webkit-transform: rotate(120deg); } .boxS { transform: rotate(-60deg); -ms-transform: rotate(-60deg); -moz-transform: rotate(-60deg); -webkit-transform: rotate(-60deg); } .boxT { transform: rotate(-60deg); background: no-repeat 50% center; background-size: 125% auto; -ms-transform: rotate(-60deg); -moz-transform: rotate(-60deg); -webkit-transform: rotate(-60deg); visibility: visible; } .overlay { transition: all 250ms ease-in-out 0s; display: none; position: relative; } .overlay:hover { background-color: rgba(0,0,0,0.6); } .boxT:hover .overlay { display: block; } .overlay a { display: inline-block; position: absolute; left: 50%; top: 50%; margin: -16px 0 0 -16px; border-radius: 3px; background-color: #d3b850; text-align: center; line-height: 32px; width: 32px; height: 32px; text-decoration: none; color: White; font-size: 18px; font-weight: bolder; } </style></head><body> <div class="box"> <!--第一行(lineFirst)--> <div class="lineF"> <div class="boxF"> <div class="boxS"> <div class="boxT" style="background-image: url(img/1.jpg);"> <div class="overlay"> <a href="#">+</a> </div> </div> </div> </div> <div class="boxF"> <div class="boxS"> <div class="boxT" style="background-image: url(img/2.jpg);"> <div class="overlay"> <a href="#">+</a> </div> </div> </div> </div> <div class="boxF"> <div class="boxS"> <div class="boxT" style="background-image: url(img/3.jpg);"> <div class="overlay"> <a href="#">+</a> </div> </div> </div> </div> </div> <!--第二行(lineSecond)--> <div class="lineS"> <div class="boxF"> <div class="boxS"> <div class="boxT" style="background-image: url(img/4.jpg);"> <div class="overlay"> <a href="#">+</a> </div> </div> </div> </div> <div class="boxF"> <div class="boxS"> <div class="boxT" style="background-image: url(img/5.jpg);"> <div class="overlay"> <a href="#">+</a> </div> </div> </div> </div> </div> </div></body></html>
If you want to see the effect, just copy the DEMO code directly. Versions below IE9 are not supported.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.
