code_junkie

What is the best way to create rounded corners using CSS?

Nov 10th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. border-radius:
  2.  
  3. .my_rounded_corners{
  4. -moz-border-radius: 5px;
  5. -webkit-border-radius: 5px;
  6. -khtml-border-radius: 5px;
  7. border-radius: 5px;
  8. }
  9.  
  10. .my_rounded_corners{
  11. border: 1px solid #ccc;
  12.  
  13. -moz-border-radius-topleft: 10px;
  14. -khtml-border-top-left-radius: 10px;
  15. -webkit-border-top-left-radius: 10px;
  16. border-top-left-radius: 10px;
  17.  
  18. -moz-border-radius-topright: 0px;
  19. -khtml-border-top-right-radius: 0px;
  20. -webkit-border-top-right-radius: 0px;
  21. border-top-right-radius: 0px;
  22.  
  23. -moz-border-radius-bottomleft: 4px;
  24. -khtml-border-bottom-left-radius: 4px;
  25. -webkit-border-bottom-left-radius: 4px;
  26. border-bottom-left-radius: 4px;
  27.  
  28. -moz-border-radius-bottomright: 10px;
  29. -khtml-border-bottom-right-radius: 10px;
  30. -webkit-border-bottom-right-radius: 10px;
  31. border-bottom-right-radius: 10px;
  32. }
  33.  
  34. div.box {
  35. background-color: yellow;
  36. border: 1px solid red;
  37. border-radius: 5px;
  38. behavior: url(corners.htc);
  39. }
  40.  
  41. -moz-border-radius: 10px;
  42. -webkit-border-radius: 10px;
  43. border-radius: 10px;
  44.  
  45. -moz-border-radius-topleft: 10px;
  46. -moz-border-radius-topright: 7px;
  47. -moz-border-radius-bottomleft: 5px;
  48. -moz-border-radius-bottomright: 3px;
  49. -webkit-border-top-right-radius: 10px;
  50. -webkit-border-top-left-radius: 7px;
  51. -webkit-border-bottom-left-radius: 5px;
  52. -webkit-border-bottom-right-radius: 3px;
  53.  
  54. <div class="Rounded">
  55. // content
  56. <div class="RoundedCorner RoundedCorner-TopLeft"></div>
  57. <div class="RoundedCorner RoundedCorner-TopRight"></div>
  58. <div class="RoundedCorner RoundedCorner-BottomRight"></div>
  59. <div class="RoundedCorner RoundedCorner-BottomLeft"></div>
  60. </div>
  61.  
  62. /********************************
  63. * Rounded styling
  64. ********************************/
  65.  
  66. .Rounded
  67. {
  68. position: relative;
  69. }
  70.  
  71. .Rounded .RoundedCorner
  72. {
  73. position: absolute;
  74.  
  75. background-image: url('SpriteSheet.png');
  76. background-repeat: no-repeat;
  77.  
  78. overflow: hidden;
  79.  
  80. /* Size of the rounded corner images */
  81. height: 5px;
  82. width: 5px;
  83. }
  84.  
  85. .Rounded .RoundedCorner-TopLeft
  86. {
  87. top: 0;
  88. left: 0;
  89.  
  90. /* No background position change (or maybe depending on your sprite sheet) */
  91. }
  92.  
  93. .Rounded .RoundedCorner-TopRight
  94. {
  95. top: 0;
  96. right: 0;
  97.  
  98. /* Move the sprite sheet to show the appropriate image */
  99. background-position: -5px 0;
  100. }
  101.  
  102. /* Hack for IE6 */
  103. * html .Rounded .RoundedCorner-TopRight
  104. {
  105. right: -1px;
  106. }
  107.  
  108. .Rounded .RoundedCorner-BottomLeft
  109. {
  110. bottom: 0;
  111. left: 0;
  112.  
  113. /* Move the sprite sheet to show the appropriate image */
  114. background-position: 0 -5px;
  115. }
  116.  
  117. /* Hack for IE6 */
  118. * html .Rounded .RoundedCorner-BottomLeft
  119. {
  120. bottom: -20px;
  121. }
  122.  
  123. .Rounded .RoundedCorner-BottomRight
  124. {
  125. bottom: 0;
  126. right: 0;
  127.  
  128. /* Move the sprite sheet to show the appropriate image */
  129. background-position: -5px -5px;
  130. }
  131.  
  132. /* Hack for IE6 */
  133. * html .Rounded .RoundedCorner-BottomRight
  134. {
  135. bottom: -20px;
  136. right: -1px;
  137. }
  138.  
  139. #round-my-corners-please {
  140. -webkit-border-radius: 20px;
  141. -moz-border-radius: 20px;
  142. border-radius: 20px;
  143. }
  144.  
  145. <div class="s">Content</div>
  146.  
  147. $("div.s")
  148. .wrapInner("<div class='s-iwrap'><div class='s-iwrap2'>")
  149. .prepend('<div class="tr"/><div class="tl"/><div class="br"/><div class="bl"/>');
  150.  
  151. /*rounded corner orange box - no title*/
  152. .s{position:relative; margin: 0 auto 15px; zoom:1;}
  153. .s-iwrap{border: 1px solid #FF9933;}
  154. .s-iwrap2{margin: 12px;}
  155. .s .br,.s .bl, .s .tl, .s .tr{
  156. background: url(css/images/orange_corners_sprite.png) no-repeat;
  157. line-height:1px;
  158. font-size:1px;
  159. width:9px;
  160. height:9px;
  161. position:absolute;}
  162. .s .br{bottom: 0; right:0; background-position: bottom right;}
  163. .s .bl{bottom: 0; left: 0;background-position: bottom left;}
  164. .s .tl{top:0; left: 0;background-position: top left;}
  165. .s .tr{top:0; right: 0;background-position: top right;}
  166.  
  167. <div class="item_with_border">
  168. <div class="border_top_left"></div>
  169. <div class="border_top_right"></div>
  170. <div class="border_bottom_left"></div>
  171. <div class="border_bottom_right"></div>
  172. This is the text that is displayed
  173. </div>
  174.  
  175. <style>
  176. div.item_with_border
  177. {
  178. border: 1px solid #FFF;
  179. postion: relative;
  180. }
  181. div.item_with_border > div.border_top_left
  182. {
  183. background-image: url(topleft.png);
  184. position: absolute;
  185. top: -1px;
  186. left: -1px;
  187. width: 30px;
  188. height: 30px;
  189. z-index: 2;
  190. }
  191. div.item_with_border > div.border_top_right
  192. {
  193. background-image: url(topright.png);
  194. position: absolute;
  195. top: -1px;
  196. right: -1px;
  197. width: 30px;
  198. height: 30px;
  199. z-index: 2;
  200. }
  201. div.item_with_border > div.border_bottom_left
  202. {
  203. background-image: url(bottomleft.png);
  204. position: absolute;
  205. bottom: -1px;
  206. left: -1px;
  207. width: 30px;
  208. height: 30px;
  209. z-index: 2;
  210. }
  211. div.item_with_border > div.border_bottom_right
  212. {
  213. background-image: url(bottomright.png);
  214. position: absolute;
  215. bottom: -1px;
  216. right: -1px;
  217. width: 30px;
  218. height: 30px;
  219. z-index: 2;
  220. }
  221. </style>
Add Comment
Please, Sign In to add comment