经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » HTML/CSS » CSS3 » 查看文章
css3实现元素环绕中心点布局的方法示例_css3_CSS
来源:jb51  时间:2019/1/16 9:30:54  对本文有异议

本文介绍了css3实现元素环绕中心点布局的方法示例,分享给大家,具体如下:

效果如图:
 

代码实现:

  1. <style>
  2. *{
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. .surround-box,
  8. .center-point{
  9. position: absolute;
  10. top: 50%;
  11. left: 50%;
  12. width: 20px;
  13. height: 20px;
  14. margin-left: -10px;
  15. margin-top: -10px;
  16. border-radius: 50%;
  17. background-color: #000;
  18. }
  19. .circle{
  20. /* 这里一定要绝对定位,这样位置才能铺开来 */
  21. position: absolute;
  22. top: -10px;
  23. left: -10px;
  24. width: 40px;
  25. height: 40px;
  26. line-height: 40px;
  27. border-radius: 50%;
  28. text-align: center;
  29. color: #fff;
  30. }
  31. .circle1{
  32. background-color: red;
  33. /* rotateZ控制方向,每个元素旋转30度,12个元素刚好360度。translateY控制每个元素距中心点的距离 */
  34. transform: rotateZ(30deg) translateY(80px);
  35. }
  36. .circle2{
  37. background-color: orange;
  38. transform: rotateZ(60deg) translateY(80px);
  39. }
  40. .circle3{
  41. background-color: yellow;
  42. transform: rotateZ(90deg) translateY(80px);
  43. }
  44. .circle4{
  45. background-color: green;
  46. transform: rotateZ(120deg) translateY(80px);
  47. }
  48. .circle5{
  49. background-color: seagreen;
  50. transform: rotateZ(150deg) translateY(80px);
  51. }
  52. .circle6{
  53. background-color: blue;
  54. transform: rotateZ(180deg) translateY(80px);
  55. }
  56. .circle7{
  57. background-color: purple;
  58. transform: rotateZ(210deg) translateY(80px);
  59. }
  60. .circle8{
  61. background-color: lightsalmon;
  62. transform: rotateZ(240deg) translateY(80px);
  63. }
  64. .circle9{
  65. background-color: deeppink;
  66. transform: rotateZ(270deg) translateY(80px);
  67. }
  68. .circle10{
  69. background-color: lightyellow;
  70. transform: rotateZ(300deg) translateY(80px);
  71. }
  72. .circle11{
  73. background-color: lightgreen;
  74. transform: rotateZ(330deg) translateY(80px);
  75. }
  76. .circle12{
  77. background-color: lightslategrey;
  78. transform: rotateZ(360deg) translateY(80px);
  79. }
  80. </style>
  1. <body>
  2. <div class="center-point"></div>
  3. <div class="surround-box">
  4. <div class="circle circle1">1</div>
  5. <div class="circle circle2">2</div>
  6. <div class="circle circle3">3</div>
  7. <div class="circle circle4">4</div>
  8. <div class="circle circle5">5</div>
  9. <div class="circle circle6">6</div>
  10. <div class="circle circle7">7</div>
  11. <div class="circle circle8">8</div>
  12. <div class="circle circle9">9</div>
  13. <div class="circle circle10">10</div>
  14. <div class="circle circle11">11</div>
  15. <div class="circle circle12">12</div>
  16. </div>
  17. </body>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号