How to set a hexagonal image in css: first create an HTML sample file; then introduce the image into the body; finally implement the image through css styles such as "transform: rotate(120deg);overflow: hidden;" Just be hexagonal.
The operating environment of this tutorial: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.
CSS3 to achieve hexagonal Div image display effect
1. Effect picture
css Video Tutorial"]
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CSS3 实现六边形图片展示效果</title> <style type="text/css"> body, p, 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> <p class="box"> <!--第一行(lineFirst)--> <p class="lineF"> <p class="boxF"> <p class="boxS"> <p class="boxT" style="background-image: url(img/1.jpg);"> <p class="overlay"> <a href="#">+</a> </p> </p> </p> </p> <p class="boxF"> <p class="boxS"> <p class="boxT" style="background-image: url(img/2.jpg);"> <p class="overlay"> <a href="#">+</a> </p> </p> </p> </p> <p class="boxF"> <p class="boxS"> <p class="boxT" style="background-image: url(img/3.jpg);"> <p class="overlay"> <a href="#">+</a> </p> </p> </p> </p> </p> <!--第二行(lineSecond)--> <p class="lineS"> <p class="boxF"> <p class="boxS"> <p class="boxT" style="background-image: url(img/4.jpg);"> <p class="overlay"> <a href="#">+</a> </p> </p> </p> </p> <p class="boxF"> <p class="boxS"> <p class="boxT" style="background-image: url(img/5.jpg);"> <p class="overlay"> <a href="#">+</a> </p> </p> </p> </p> </p> </p></body></html>
The above is the detailed content of How to set the image to hexagon in css. For more information, please follow other related articles on the PHP Chinese website!