Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (e.g. Greenland, Europe, Africa). I want to create map like here with using CSS3 and HTML5.

Here is link to an example image:

like image 786
Rafath Avatar asked Aug 26 '12 00:08

Rafath


People also ask

How do you make an irregular shape with HTML and CSS?

HTML & CSS Answer This can be done by using perspective and transform . You create two divs: one that will get the perspective and one that will be transformed. Just know that anything in the . test -div will also be transformed, so if you put text in there, it will also get transformed.

Can you make shapes in CSS?

For the Level 1 specification, CSS Shapes can be applied to floating elements. The specification defines a number of different ways to define a shape on a floated element, causing wrapping lines to wrap round the shape rather than following the rectangle of the element's box.


2 Answers

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 { 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... -->
like image 115
Ana Avatar answered Oct 02 '22 06:10

Ana


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/

like image 33
Navaneeth Avatar answered Oct 02 '22 07:10

Navaneeth