最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Create custom div element with special shape dynamically - Stack Overflow

programmeradmin3浏览0评论

I want to create some shapes like this :

These are 3 shapes.Then i want put some element on this shape. I try to using border-radius property but it can't generate this shape. Also i try to use <img> , <map> and <area> but i have problem with put elements on it. What's your idea about it?

I want to create some shapes like this :

These are 3 shapes.Then i want put some element on this shape. I try to using border-radius property but it can't generate this shape. Also i try to use <img> , <map> and <area> but i have problem with put elements on it. What's your idea about it?

Share Improve this question edited Apr 14, 2013 at 8:29 Saman Gholami asked Apr 14, 2013 at 8:01 Saman GholamiSaman Gholami 3,5127 gold badges33 silver badges72 bronze badges 3
  • Use the <canves> tag, lets you paint inside a block element, i think its the easiest way to achieve what you desire. – Imperative Commented Apr 14, 2013 at 8:33
  • @Imperative you mean using HTML5?could you make a sample?what about browser patibility with this element? – Saman Gholami Commented Apr 14, 2013 at 8:36
  • 2 have look at this page: lots of samples: html5canvastutorials./tutorials/… – Imperative Commented Apr 14, 2013 at 8:49
Add a ment  | 

1 Answer 1

Reset to default 7

You just gotta be creative:

HTML:

<div id="circle">
    <div id="cover"></div>        
    <div id="innerCircle">     
        <div id="rect1"></div>
        <div id="rect2"></div>
    </div>
</div>

CSS:

   #circle { 
       width: 140px;
       height: 140px;
       background: red; 
       -moz-border-radius: 70px; 
       -webkit-border-radius: 70px; 
       border-radius: 70px;
        margin: 0 auto;
        position: relative;
        top: -50px;
    }

    #innerCircle { 
       width: 90px;
       height: 90px;
       background: white; 
       -moz-border-radius: 70px; 
       -webkit-border-radius: 70px; 
       border-radius: 70px;
        position: absolute;
        top: 25px;
        right: 25px;
    }

    #rect1 {
        width: 20px; 
       height: 90px; 
       background: white;
    transform: rotate(30deg);
    -ms-transform: rotate(30deg); /* IE 9 */
    -webkit-transform: rotate(30deg); /* Safari and Chrome */
        position: absolute;
        top: 50%;
        left: 5px;
    }

    #rect2 {
       width: 20px; 
       height: 90px; 
       background: white;
    transform: rotate(-30deg);
    -ms-transform: rotate(-30deg); /* IE 9 */
    -webkit-transform: rotate(-30deg); /* Safari and Chrome */
        position: absolute;
        top: 50%;
        right: 5px;
    }

    #cover {
       width: 150px; 
       height: 80px; 
       background: white;
        position: absolute;
        top: 0px;
        left: 0px;
    }

http://jsfiddle/bnSe7/

Or you can do something like this, curving the sides and using CSS3 rotate features to get the three shapes:

http://jsfiddle/RqWtC/1/

You will probably have to use HTML5 canvas to achieve the exact plex shapes you're requesting:

http://www.html5canvastutorials./tutorials/html5-canvas-custom-shapes/

发布评论

评论列表(0)

  1. 暂无评论