CSS3の新たなプロパティ「transform」と「border-radius」を使って、CSSのみでいろんなカタチを表現できるようになりました。すべてを暗記するのも大変なのでコピペで再利用できるようにメモしておきたいと思います。
- 正方形 -Square-
- 長方形 -Rectangle-
- 円形 -circle-
- 楕円形 -oval-
- 三角形(上) -Triangle Up-
- 三角形(下) -Triangle Down-
- 三角形(右) -Triangle Right-
- 三角形(左) -Triangle Left-
- 三角形(左上) -Triangle TopLeft-
- 三角形(右上) -Triangle Topright-
- 三角形(左下) -Triangle BottomLeft-
- 三角形(右下) -Triangle Bottomright-
- 湾曲した矢印 -Curved Tail Arrow-
- 台形 -Trapezoid-
- 平行四辺形 -Parallelogram-
- 星型 -6points-
- 星型 -5points-
- ペンタゴン -Pentagon-
- 六角ヘキサゴン -Hexagon-
- 八角オクタゴン -Octagon-
- ハート型 -Heart-
- 無限大 -Infinity-
- ひし形 -Diamond Square-
- ひし形(鋭)-Diamond Narrow-
- 卵型-Egg-
- パックマン型-PacMan-
- 会話吹き出し-TalkBubble-
- ポイントバースト-PointBurst-
- TVスクリーン-TV Screen-
- 拡大鏡-MagnifyingGlass-
- 月-Moon-
- フラグ-Flag-
1.正方形 -Square-
1 2 3 4 5 6 |
/* 正方形 */ #square { width:50px; height:50px; background:#81C7D4; } |
2.長方形 -Rectangle-
1 2 3 4 5 6 |
/* 長方形 */ #rectangle { width:100px; height:50px; background:#81C7D4; } |
3.円形 -circle-
1 2 3 4 5 6 7 8 9 |
/* 円形 */ #circle { width:50px; height:50px; background:#81C7D4; -moz-border-radius: 25px; -webkit-border-radius: 25px; border-radius: 25px; /* 横幅&高さの1/2 */ } |
4.楕円形 -oval-
1 2 3 4 5 6 7 8 9 |
/* 楕円形 */ #oval { width:100px; height:50px; background:#81C7D4; -moz-border-radius: 50px / 25px; /* 高さ÷2 */ -webkit-border-radius: 50px / 25px; border-radius: 50px / 25px; } |
5.三角形(上) -Triangle Up-
1 2 3 4 5 6 7 8 |
/* 三角形(上) */ #triangle-up { width: 0; height: 0; border-left: 25px solid transparent; border-right: 25px solid transparent; border-bottom: 50px solid #81C7D4; } |
6.三角形(下) -Triangle Down-
1 2 3 4 5 6 7 8 |
/* 三角形(下) */ #triangle-down { width: 0; height: 0; border-left: 25px solid transparent; border-right: 25px solid transparent; border-top: 50px solid #81C7D4; } |
7.三角形(右) -Triangle Right-
1 2 3 4 5 6 7 8 |
/* 三角形(右) */ #triangle-right { width: 0; height: 0; border-top: 25px solid transparent; border-bottom: 25px solid transparent; border-left: 50px solid #81C7D4; } |
8.三角形(左) -Triangle Left-
1 2 3 4 5 6 7 8 |
/* 三角形(左) */ #triangle-left { width: 0; height: 0; border-top: 25px solid transparent; border-bottom: 25px solid transparent; border-right: 50px solid #81C7D4; } |
9.三角形(左上) -Triangle TopLeft-
1 2 3 4 5 6 7 |
/* 三角形(左上) */ #triangle-topleft { width: 0; height: 0; border-right: 50px solid transparent; border-top: 50px solid #81C7D4; } |
10.三角形(右上) -Triangle Topright-
1 2 3 4 5 6 7 |
/* 三角形(右上) */ #triangle-topright { width: 0; height: 0; border-left: 50px solid transparent; border-top: 50px solid #81C7D4; } |
11.三角形(左下) -Triangle BottomLeft-
1 2 3 4 5 6 7 |
/* 三角形(左下) */ #triangle-bottomleft { width: 0; height: 0; border-right: 50px solid transparent; border-bottom: 50px solid #81C7D4; } |
12.三角形(右下) -Triangle Bottomright-
1 2 3 4 5 6 7 |
/* 三角形(右下) */ #triangle-bottomright { width: 0; height: 0; border-left: 50px solid transparent; border-bottom: 50px solid #81C7D4; } |
13.湾曲した矢印 -Curved Tail Arrow-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
/* 湾曲した矢印 */ #curvedarrow { position: relative; width: 0; height: 0; border-top: 9px solid transparent; border-right: 9px solid #81C7D4; -webkit-transform: rotate(10deg); -moz-transform: rotate(10deg); -ms-transform: rotate(10deg); -o-transform: rotate(10deg); } #curvedarrow:after { content: ""; position: absolute; border: 0 solid transparent; border-top: 3px solid #81C7D4; border-radius: 20px 0 0 0; top: -12px; left: -9px; width: 12px; height: 12px; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); } |
14.台形 -Trapezoid-
1 2 3 4 5 6 7 8 |
/* 台形 */ #trapezoid { border-bottom: 50px solid #81C7D4; border-left: 25px solid transparent; border-right: 25px solid transparent; height: 0; width: 50px; } |
15.平行四辺形 -Parallelogram-
1 2 3 4 5 6 7 8 9 |
/* 平行四辺形 */ #parallelogram { width: 100px; height: 50px; -webkit-transform: skew(20deg); -moz-transform: skew(20deg); -o-transform: skew(20deg); background: #81C7D4; } |
16.星型 -6points-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/* 星型(6点) */ #star-six { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 100px solid #81C7D4; position: relative; } #star-six:after { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-top: 100px solid #81C7D4; position: absolute; content: ""; top: 30px; left: -50px; } |
17.星型 -5points-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
/* 星型(5点) */ #star-five { margin: 50px 0; position: relative; display: block; color: #81C7D4; width: 0px; height: 0px; border-right: 100px solid transparent; border-bottom: 70px solid #81C7D4; border-left: 100px solid transparent; -moz-transform: rotate(35deg); -webkit-transform: rotate(35deg); -ms-transform: rotate(35deg); -o-transform: rotate(35deg); } #star-five:before { border-bottom: 80px solid #81C7D4; border-left: 30px solid transparent; border-right: 30px solid transparent; position: absolute; height: 0; width: 0; top: -45px; left: -65px; display: block; content: ''; -webkit-transform: rotate(-35deg); -moz-transform: rotate(-35deg); -ms-transform: rotate(-35deg); -o-transform: rotate(-35deg); } #star-five:after { position: absolute; display: block; color: #81C7D4; top: 3px; left: -105px; width: 0px; height: 0px; border-right: 100px solid transparent; border-bottom: 70px solid #81C7D4; border-left: 100px solid transparent; -webkit-transform: rotate(-70deg); -moz-transform: rotate(-70deg); -ms-transform: rotate(-70deg); -o-transform: rotate(-70deg); content: ''; } |
18.ペンタゴン -Pentagon-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/* ペンタゴン */ #pentagon { position: relative; width: 54px; border-width: 50px 18px 0; border-style: solid; border-color: #81C7D4 transparent; } #pentagon:before { content: ""; position: absolute; height: 0; width: 0; top: -85px; left: -18px; border-width: 0 45px 35px; border-style: solid; border-color: transparent transparent #81C7D4; } |
19.六角ヘキサゴン -Hexagon-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* 六角ヘキサゴン */ #hexagon { width: 100px; height: 55px; background: #81C7D4; position: relative; } #hexagon:before { content: ""; position: absolute; top: -25px; left: 0; width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 25px solid #81C7D4; } #hexagon:after { content: ""; position: absolute; bottom: -25px; left: 0; width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-top: 25px solid #81C7D4; } |
20.八角オクタゴン -Octagon-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/* 八角オクタゴン */ #octagon { width: 100px; height: 100px; background: #81C7D4; position: relative; } #octagon:before { content: ""; position: absolute; top: 0; left: 0; border-bottom: 29px solid #81C7D4; border-left: 29px solid #eee; border-right: 29px solid #eee; width: 42px; height: 0; } #octagon:after { content: ""; position: absolute; bottom: 0; left: 0; border-top: 29px solid #81C7D4; border-left: 29px solid #eee; border-right: 29px solid #eee; width: 42px; height: 0; } |
21.ハート型 -Heart-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
/* ハート型 */ #heart { position: relative; width: 100px; height: 90px; } #heart:before, #heart:after { position: absolute; content: ""; left: 50px; top: 0; width: 50px; height: 80px; background: #81C7D4; -moz-border-radius: 50px 50px 0 0; border-radius: 50px 50px 0 0; -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -ms-transform: rotate(-45deg); -o-transform: rotate(-45deg); transform: rotate(-45deg); -webkit-transform-origin: 0 100%; -moz-transform-origin: 0 100%; -ms-transform-origin: 0 100%; -o-transform-origin: 0 100%; transform-origin: 0 100%; } #heart:after { left: 0; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); -webkit-transform-origin: 100% 100%; -moz-transform-origin: 100% 100%; -ms-transform-origin: 100% 100%; -o-transform-origin: 100% 100%; transform-origin :100% 100%; } |
22.無限大 -Infinity-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* 無限大 */ #infinity { position: relative; width: 212px; height: 100px; } #infinity:before, #infinity:after { content: ""; position: absolute; top: 0; left: 0; width: 60px; height: 60px; border: 20px solid #81C7D4; -moz-border-radius: 50px 50px 0 50px; border-radius: 50px 50px 0 50px; -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -ms-transform: rotate(-45deg); -o-transform: rotate(-45deg); transform: rotate(-45deg); } #infinity:after { left: auto; right: 0; -moz-border-radius: 50px 50px 50px 0; border-radius: 50px 50px 50px 0; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); } |
23.ひし形 -Diamond Square-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/* ひし形 */ #diamond { width: 0; height: 0; border: 50px solid transparent; border-bottom-color: #81C7D4; position: relative; top: -50px; } #diamond:after { content: ''; position: absolute; left: -50px; top: 50px; width: 0; height: 0; border: 50px solid transparent; border-top-color: #81C7D4; } |
24.ひし形(鋭)-Diamond Narrow-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/* ひし形(鋭) */ #diamond-narrow { width: 0; height: 0; border: 50px solid transparent; border-bottom: 70px solid #81C7D4; position: relative; top: -50px; } #diamond-narrow:after { content: ''; position: absolute; left: -50px; top: 70px; width: 0; height: 0; border: 50px solid transparent; border-top: 70px solid #81C7D4; } |
25.卵型-Egg-
1 2 3 4 5 6 7 8 9 |
/* 卵型 */ #egg { display:block; width: 126px; height: 180px; background-color: #81C7D4; -webkit-border-radius: 63px 63px 63px 63px / 108px 108px 72px 72px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; } |
26.パックマン型-PacMan-
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/* パックマン型 */ #pacman { width: 0px; height: 0px; border-right: 60px solid transparent; border-top: 60px solid #81C7D4; border-left: 60px solid #81C7D4; border-bottom: 60px solid #81C7D4; border-top-left-radius: 60px; border-top-right-radius: 60px; border-bottom-left-radius: 60px; border-bottom-right-radius: 60px; } |
27.会話吹き出し-TalkBubble-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* 会話吹き出し */ #talkbubble { width: 120px; height: 80px; background: #81C7D4; position: relative; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; } #talkbubble:before { content:""; position: absolute; right: 100%; top: 26px; width: 0; height: 0; border-top: 13px solid transparent; border-right: 26px solid #81C7D4; border-bottom: 13px solid transparent; } |
28.ポイントバースト-PointBurst-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* ポイントバースト */ #burst-12 { background: #81C7D4; width: 80px; height: 80px; position: relative; text-align: center; } #burst-12:before, #burst-12:after { content: ""; position: absolute; top: 0; left: 0; height: 80px; width: 80px; background: #81C7D4; } #burst-12:before { -webkit-transform: rotate(30deg); -moz-transform: rotate(30deg); -ms-transform: rotate(30deg); -o-transform: rotate(30deg); } #burst-12:after { -webkit-transform: rotate(60deg); -moz-transform: rotate(60deg); -ms-transform: rotate(60deg); -o-transform: rotate(60deg); } |
29.TVスクリーン-TV Screen-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* TVスクリーン */ #tv { position: relative; width: 200px; height: 150px; margin: 20px 0; background: #81C7D4; border-radius: 50% / 10%; color: white; text-align: center; text-indent: .1em; } #tv:before { content: ''; position: absolute; top: 10%; bottom: 10%; right: -5%; left: -5%; background: inherit; border-radius: 5% / 50%; } |
30.拡大鏡-MagnifyingGlass-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
/* 拡大鏡 */ #magnifying-glass { font-size: 10em; /* This controls the size. */ display: inline-block; width: 0.4em; height: 0.4em; border: 0.1em solid #81C7D4; position: relative; border-radius: 0.35em; } #magnifying-glass::before { content: ""; display: inline-block; position: absolute; right: -0.25em; bottom: -0.1em; border-width: 0; background: #81C7D4; width: 0.35em; height: 0.08em; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); } |
31.月-Moon-
1 2 3 4 5 6 7 |
/* 月 */ #moon { width: 80px; height: 80px; border-radius: 50%; box-shadow: 15px 15px 0 0 #81C7D4; } |
32.フラグ-Flag-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/* フラグ */ #flag { width: 110px; height: 56px; padding-top: 15px; position: relative; background: #81C7D4; color: white; font-size: 11px; letter-spacing: 0.2em; text-align: center; text-transform: uppercase; } #flag:after { content: ""; position: absolute; left: 0; bottom: 0; width: 0; height: 0; border-bottom: 40px solid #eee; border-left: 55px solid transparent; border-right: 55px solid transparent; } |
ずらずら~っと、羅列になってしまいましたが使いたい時に、サイズや色を変更しながら再利用できそうですね。
以上になります。
▼こちらを参考にさせて頂きました
css-tricks / The Shapes of CSS