简体   繁体   English

如何使用css3和html5制作不规则形状的div?

[英]How can I make a div with irregular shapes with css3 and html5?

I'm wondering is there any possibility to build div with irregular shapes, something, similar to this (eg Greenland, Europe, Africa).我想知道有没有可能用不规则的形状来构建 div,类似于这个(例如格陵兰、欧洲、非洲)。 I want to create map like here with using CSS3 and HTML5.我想使用 CSS3 和 HTML5 创建像这里这样的地图。

Here is link to an example image:这是示例图像的链接:

What you have there looks like a grid, which you can obtain either with many gradients on a div, either with a grid of many divs on which you apply CSS transforms.您拥有的看起来像一个网格,您可以在 div 上使用许多渐变获得它,或者使用在其上应用 CSS 转换的许多 div 的网格。

 div { box-sizing: border-box; } .container { overflow: hidden; width: 32em; height: 32em; margin: 5.6em auto 0; background: silver; } .grid { transform: skewX(-45deg) rotate(15deg) scaleX(1.785) scaleY(.8) translateX(-4.5em) translateY(-3em); } .grid-row { width: 32em; height: 2em; } .grid-cell { float: left; width: 2em; height: 2em; } .high { background: gainsboro; } .high:hover { background: whitesmoke; }
 <div class='container'> <div class='grid'> <div class='grid-row'> <div class='grid-cell'></div> <div class='grid-cell high'></div> </div> <div class='grid-row'> <div class='grid-cell'></div> <div class='grid-cell high'></div> </div> </div> </div> <!-- and so on... -->

Elements have always been rectangular.元素一直是矩形的。 Still, you can simulate other shapes by drawing CSS shapes within the rectangular division and by arranging different divisions (with z-index, etc.).不过,您可以通过在矩形分区内绘制 CSS 形状并通过排列不同的分区(使用 z-index 等)来模拟其他形状。 This will help you:这将帮助您:

http://css-tricks.com/examples/ShapesOfCSS/ http://css-tricks.com/examples/ShapesOfCSS/

如果你想要制作精确的不规则边框,那就去找HTML图像图(比css和绝对定位更好的解决方案),试试这个http://www.svennerberg.com/examples/imagemap_rollover/

您应该能够使用您选择的任何元素将地图创建为正方形,然后将整个内容包装在 div/span/whatever 中并执行 css3 3d 转换以使其符合您的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM