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

安稳与你 提交于 2019-11-26 13:46:00

问题


I'm wondering is there any possibility to build div with irregular shapes, something, similar to this (e.g. Greenland, Europe, Africa). I want to create map like here with using CSS3 and HTML5.

Here is link to an example image:


回答1:


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.). This will help you:

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




回答2:


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 (DEMO).

HTML:

<div class='container'>
    <div class='grid'>
        <div class='grid-row'>
            <div class='grid-cell'></div>
            <div class='grid-cell high'></div>
<!-- and so on... -->

CSS:

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;
}



回答3:


if you want exact irregular borders to be made,go for HTML image maps(still a better solution than css and absolute positioning) , try this http://www.svennerberg.com/examples/imagemap_rollover/




回答4:


You should be able to create your map as squares, with whatever elements you choose, and then wrap the whole thing in a div/span/whatever and perform a css3 3d transform to get it how you need it.



来源:https://stackoverflow.com/questions/12126731/how-can-i-make-a-div-with-irregular-shapes-with-css3-and-html5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!