17-CSS3的常见边框汇总

CSS3 常见边框汇总

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>CSS3 边框</title>
  6. <style>
  7. body, ul, li, dl, dt, dd, h1, h2, h3, h4, h5 {
  8. margin: 0;
  9. padding: 0;
  10. }
  11. body {
  12. background-color: #F7F7F7;
  13. }
  14. .wrapper {
  15. width: 1000px;
  16. margin: 0 auto;
  17. padding: 20px;
  18. box-sizing: border-box;
  19. }
  20. header {
  21. padding: 20px 0;
  22. margin-bottom: 20px;
  23. text-align: center;
  24. }
  25. header h3 {
  26. line-height: 1;
  27. font-weight: normal;
  28. font-size: 28px;
  29. }
  30. .main {
  31. /*overflow: hidden;*/
  32. }
  33. .main:after {
  34. content: '';
  35. clear: both;
  36. display: block;
  37. }
  38. .main .item {
  39. width: 210px;
  40. height: 210px;
  41. margin: 0 30px 30px 0;
  42. display: flex;
  43. position: relative;
  44. background-color: #FFF;
  45. float: left;
  46. box-shadow: 2px 2px 5px #CCC;
  47. }
  48. .main .item:after {
  49. content: attr(data-brief);
  50. display: block;
  51. width: 100%;
  52. height: 100%;
  53. text-align: center;
  54. line-height: 210px;
  55. position: absolute;
  56. top: 0;
  57. left: 0;
  58. color: #FFF;
  59. font-family: '微软雅黑';
  60. font-size: 18px;
  61. background-color: rgba(170, 170, 170, 0);
  62. z-index: -1;
  63. transition: all 0.3s ease-in;
  64. }
  65. .main .item:hover:after {
  66. background-color: rgba(170, 170, 170, 0.6);
  67. z-index: 100;
  68. }
  69. .main .item:nth-child(4n) {
  70. margin-right: 0;
  71. }
  72. /*.main .item:nth-last-child(-n+5) {
  73. margin-bottom: 0;
  74. }*/
  75. /* 以上是骨架样式 */
  76. /* 1、2、3、4 顺时针 */
  77. .border-radius {
  78. width: 180px;
  79. height: 180px;
  80. margin: auto;
  81. border: 1px solid red;
  82. /*border-radius: 50% 30% 20%;*/
  83. }
  84. .square {
  85. border-radius: 0;
  86. }
  87. /*拱形*/
  88. .item:nth-child(1) .border-radius {
  89. border-radius: 90px;
  90. }
  91. /*拱形*/
  92. .item:nth-child(2) .border-radius {
  93. border-radius: 90px 90px 0 0;
  94. }
  95. /*半圆*/
  96. .item:nth-child(3) .border-radius {
  97. height: 90px;
  98. border-radius: 90px 90px 0 0;
  99. }
  100. /*左上角*/
  101. .item:nth-child(4) .border-radius {
  102. /*height: 90px;*/
  103. border-radius: 90px 0 0 0;
  104. }
  105. /*四分之一圆*/
  106. .item:nth-child(5) .border-radius {
  107. width: 90px;
  108. height: 90px;
  109. border-radius: 90px 0 0 0;
  110. }
  111. /*横着的椭圆*/
  112. .item:nth-child(6) .border-radius {
  113. height: 90px;
  114. /*border-radius: 50%;*/
  115. border-radius: 90px 90px 90px 90px / 45px 45px 45px 45px;
  116. /*border-radius: 45px / 90px;*/
  117. }
  118. /*竖着的椭圆*/
  119. .item:nth-child(7) .border-radius {
  120. width: 90px;
  121. border-radius: 45px 45px 45px 45px / 90px 90px 90px 90px;
  122. }
  123. /*半个横着的椭圆*/
  124. .item:nth-child(8) .border-radius {
  125. height: 45px;
  126. border-radius: 90px 90px 0 0 / 45px 45px 0 0;
  127. }
  128. /*半个竖着的椭圆*/
  129. .item:nth-child(9) .border-radius {
  130. width: 45px;
  131. border-radius: 45px 0 0 45px / 90px 0 0 90px;
  132. }
  133. /*四分之一竖着的椭圆*/
  134. .item:nth-child(10) .border-radius {
  135. width: 45px;
  136. height: 90px;
  137. border-radius: 45px 0 0 0 / 90px 0 0 0;
  138. }
  139. /*饼环*/
  140. .item:nth-child(11) .border-radius {
  141. width: 40px;
  142. height: 40px;
  143. border: 70px solid red;
  144. border-radius: 90px;
  145. }
  146. /*圆饼*/
  147. .item:nth-child(12) .border-radius {
  148. width: 40px;
  149. height: 40px;
  150. border: 70px solid red;
  151. border-radius: 60px;
  152. }
  153. /*左上角圆饼*/
  154. .item:nth-child(13) .border-radius {
  155. width: 60px;
  156. height: 60px;
  157. border: 60px solid red;
  158. border-radius: 90px 0 0 0;
  159. }
  160. /*对角圆饼*/
  161. .item:nth-child(14) .border-radius {
  162. width: 60px;
  163. height: 60px;
  164. border: 60px solid red;
  165. border-radius: 90px 0 90px 0;
  166. }
  167. /*四边不同色*/
  168. .item:nth-child(15) .border-radius {
  169. width: 0px;
  170. height: 0px;
  171. border-width: 90px;
  172. border-style: solid;
  173. border-color: red green yellow blue;
  174. }
  175. /*右透明色*/
  176. .item:nth-child(16) .border-radius {
  177. width: 0px;
  178. height: 0px;
  179. border-width: 90px;
  180. border-style: solid;
  181. border-color: red green yellow blue;
  182. border-right-color: transparent;
  183. }
  184. /*圆右透明色*/
  185. .item:nth-child(17) .border-radius {
  186. width: 0px;
  187. height: 0px;
  188. border-width: 90px;
  189. border-style: solid;
  190. border-color: red;
  191. border-right-color: transparent;
  192. border-radius: 90px;
  193. }
  194. /*圆右红透明色*/
  195. .item:nth-child(18) .border-radius {
  196. width: 0px;
  197. height: 0px;
  198. border-width: 90px;
  199. border-style: solid;
  200. border-color: transparent;
  201. border-right-color: red;
  202. border-radius: 90px;
  203. }
  204. /*阴阳图前世*/
  205. .item:nth-child(19) .border-radius {
  206. width: 180px;
  207. height: 0px;
  208. border-top-width: 90px;
  209. border-bottom-width: 90px;
  210. border-style: solid;
  211. border-top-color: red;
  212. border-bottom-color: green;
  213. /*border-right-color: red;*/
  214. border-radius: 90px;
  215. }
  216. /*阴阳图前世2*/
  217. .item:nth-child(20) .border-radius {
  218. width: 180px;
  219. height: 90px;
  220. border-bottom-width: 90px;
  221. border-style: solid;
  222. border-bottom-color: green;
  223. background-color: red;
  224. /*border-right-color: red;*/
  225. border-radius: 90px;
  226. }
  227. /*阴阳图今生*/
  228. .item:nth-child(21) .border-radius {
  229. width: 180px;
  230. height: 90px;
  231. border-bottom-width: 90px;
  232. border-style: solid;
  233. border-bottom-color: green;
  234. background-color: red;
  235. border-radius: 90px;
  236. position: relative;
  237. }
  238. .item:nth-child(21) .border-radius::after,
  239. .item:nth-child(21) .border-radius::before {
  240. content: '';
  241. position: absolute;
  242. top: 50%;
  243. width: 20px;
  244. height: 20px;
  245. /*margin: -10px 0 0 0;*/
  246. border-width: 35px;
  247. border-style: solid;
  248. border-radius: 45px;
  249. }
  250. /*左阴阳*/
  251. .item:nth-child(21) .border-radius::after {
  252. background-color: red;
  253. border-color: green;
  254. }
  255. /*右阴阳*/
  256. .item:nth-child(21) .border-radius::before {
  257. background-color: green;
  258. border-color: red;
  259. right: 0;
  260. }
  261. /*右阴阳*/
  262. .item:nth-child(22) .border-radius {
  263. width: 180px;
  264. height: 90px;
  265. border-bottom-width: 90px;
  266. border-bottom-color: green;
  267. border-bottom-style: solid;
  268. background-color: red;
  269. border-radius: 90px;
  270. position: relative;
  271. }
  272. .item:nth-child(22) .border-radius::after,
  273. .item:nth-child(22) .border-radius::before {
  274. content: '';
  275. position: absolute;
  276. top: 50%;
  277. width: 20px;
  278. height: 20px;
  279. border-width: 35px;
  280. border-style: solid;
  281. border-radius: 45px;
  282. }
  283. .item:nth-child(22) .border-radius::before {
  284. border-color: green;
  285. background-color: red;
  286. }
  287. .item:nth-child(22) .border-radius::after {
  288. right: 0;
  289. border-color: red;
  290. background-color: green;
  291. }
  292. /*消息框*/
  293. .item:nth-child(23) .border-radius {
  294. width: 160px;
  295. height: 80px;
  296. background-color: red;
  297. border-radius: 6px;
  298. position: relative;
  299. }
  300. .item:nth-child(23) .border-radius::after {
  301. content: '';
  302. width: 0;
  303. height: 0;
  304. border-width: 10px;
  305. border-style: solid;
  306. border-color: transparent;
  307. border-right-color: red;
  308. position: absolute;
  309. top: 16px;
  310. left: -20px;
  311. }
  312. /*奇怪的图形*/
  313. .item:nth-child(24) .border-radius {
  314. width: 40px;
  315. height: 40px;
  316. border-width: 45px 0 45px 70px;
  317. border-style: solid;
  318. border-radius: 0 0 60px 0;
  319. border-color: red;
  320. }
  321. /*奇怪的图形2*/
  322. .item:nth-child(25) .border-radius {
  323. width: 100px;
  324. height: 40px;
  325. border-width: 45px 20px 45px 70px;
  326. border-style: solid;
  327. border-radius: 60px;
  328. border-color: red;
  329. }
  330. /*QQ对话*/
  331. .item:nth-child(26) .border-radius {
  332. width: 160px;
  333. height: 80px;
  334. background-color: red;
  335. border-radius: 6px;
  336. position: relative;
  337. }
  338. .item:nth-child(26) .border-radius::after {
  339. content: '';
  340. position: absolute;
  341. top: 0;
  342. right: -20px;
  343. width: 30px;
  344. height: 30px;
  345. border-width: 0 0 30px 30px;
  346. border-style: solid;
  347. border-bottom-color: red;
  348. border-left-color: transparent;
  349. border-radius: 0 0 60px 0;
  350. }
  351. /*圆角的百分比设置 */
  352. .item:nth-child(27) .border-radius {
  353. width: 180px;
  354. /*height: 180px;*/
  355. height: 90px;
  356. border-radius: 50%;
  357. border-radius: 90px/45px;
  358. /*百分比是按横竖两个对应的方向的长度进行计算*/
  359. }
  360. </style>
  361. </head>
  362. <body>
  363. <div class="wrapper">
  364. <header>
  365. <h3>CSS3 边框圆角</h3>
  366. </header>
  367. <div class="main">
  368. <div class="item" data-brief="整圆">
  369. <div class="border-radius"></div>
  370. </div>
  371. <div class="item" data-brief="拱形">
  372. <div class="border-radius"></div>
  373. </div>
  374. <div class="item" data-brief="半圆">
  375. <div class="border-radius"></div>
  376. </div>
  377. <div class="item" data-brief="左上角">
  378. <div class="border-radius"></div>
  379. </div>
  380. <div class="item" data-brief="四分之一圆">
  381. <div class="border-radius"></div>
  382. </div>
  383. <div class="item" data-brief="横着的椭圆">
  384. <div class="border-radius"></div>
  385. </div>
  386. <div class="item" data-brief="竖着的椭圆">
  387. <div class="border-radius"></div>
  388. </div>
  389. <div class="item" data-brief="半个横着的椭圆">
  390. <div class="border-radius"></div>
  391. </div>
  392. <div class="item" data-brief="半个竖着的椭圆">
  393. <div class="border-radius"></div>
  394. </div>
  395. <div class="item" data-brief="四分之一竖着的椭圆">
  396. <div class="border-radius"></div>
  397. </div>
  398. <div class="item" data-brief="饼环">
  399. <div class="border-radius"></div>
  400. </div>
  401. <div class="item" data-brief="圆饼">
  402. <div class="border-radius"></div>
  403. </div>
  404. <div class="item" data-brief="左上角圆饼">
  405. <div class="border-radius"></div>
  406. </div>
  407. <div class="item" data-brief="对角圆饼">
  408. <div class="border-radius"></div>
  409. </div>
  410. <div class="item" data-brief="四边不同色">
  411. <div class="border-radius"></div>
  412. </div>
  413. <div class="item" data-brief="右透明色">
  414. <div class="border-radius"></div>
  415. </div>
  416. <div class="item" data-brief="圆右透明色">
  417. <div class="border-radius"></div>
  418. </div>
  419. <div class="item" data-brief="圆右红透明色">
  420. <div class="border-radius"></div>
  421. </div>
  422. <div class="item" data-brief="阴阳图前世">
  423. <div class="border-radius"></div>
  424. </div>
  425. <div class="item" data-brief="阴阳图前世2">
  426. <div class="border-radius"></div>
  427. </div>
  428. <div class="item" data-brief="阴阳图今生">
  429. <div class="border-radius"></div>
  430. </div>
  431. <div class="item" data-brief="阴阳图今生2">
  432. <div class="border-radius"></div>
  433. </div>
  434. <div class="item" data-brief="消息框">
  435. <div class="border-radius"></div>
  436. </div>
  437. <div class="item" data-brief="奇怪的图形">
  438. <div class="border-radius"></div>
  439. </div>
  440. <div class="item" data-brief="奇怪的图形2">
  441. <div class="border-radius"></div>
  442. </div>
  443. <div class="item" data-brief="QQ对话">
  444. <div class="border-radius"></div>
  445. </div>
  446. <div class="item" data-brief="圆角百分比">
  447. <div class="border-radius"></div>
  448. </div>
  449. </div>
  450. </div>
  451. </body>
  452. </html>

效果如下:

17-CSS3的常见边框汇总 - 图1

爱心

  1. <!DOCTYPE html>
  2. <html>
  3. <head lang="en">
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style>
  7. .heart {
  8. width: 200px;
  9. height: 300px;
  10. /*border: 1px solid #000;*/
  11. margin: 100px auto;
  12. position: relative;
  13. }
  14. .heart::before, .heart::after {
  15. content: "左一半";
  16. width: 100%;
  17. height: 100%;
  18. position: absolute;
  19. background-color: red;
  20. left: 0;
  21. top: 0;
  22. border-radius: 100px 100px 0 0;
  23. transform: rotate(-45deg);
  24. text-align: center;
  25. line-height: 100px;
  26. color: yellow;
  27. font-size: 30px;
  28. font-family: "MIcrosoft Yahei";
  29. }
  30. .heart::after {
  31. content: "右一半";
  32. left: 71px;
  33. transform: rotate(45deg);
  34. }
  35. </style>
  36. </head>
  37. <body>
  38. <div class="heart">
  39. </div>
  40. </body>
  41. </html>

效果如下:

17-CSS3的常见边框汇总 - 图2

它其实是下面这两个盒子叠起来的:

17-CSS3的常见边框汇总 - 图3

改变 .heart::after 的 left值,即可叠起来。