使用CSS3的圈子中的细分 [英] Segments in a circle using CSS3

查看:140
本文介绍了使用CSS3的圈子中的细分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你可以使用border radius hack在CSS3中制作一个圆圈。但是有没有办法让他们有这样的图片段?有没有办法通过HTML和CSS而不是JS?

I know you can make a circle in CSS3 using the border radius hack. But is there any way to make them have segments like this picture? Is there a way of doing this through HTML and CSS but not JS?

推荐答案

是的,你可以使用以下两种方法:

Yes, you can get such slices of custom angles using either one of the following two methods:


  1. 如果你不需要切片是元素本身,你可以简单地用一个元素和线性渐变 - 请参阅上个月我 彩虹轮

  2. 如果您需要将切片设为元素,则可以通过链接旋转和扭曲变换来执行此操作 - 请参阅此 圆形菜单 我之前做过。

  1. If you don't need the slices to be elements themselves, the you can simply do it with one element and linear gradients - see this rainbow wheel I did last month.
  2. If you need the slices to be elements themselves, then you can do it by chaining rotate and skew transforms - see this circular menu I did a while ago.

对于#2,另见这个非常简化的 示例 我现在做了。

For #2, see also this very much simplified example I did right now.

.pie {
  position: relative;
  margin: 1em auto;
  border: dashed 1px;
  padding: 0;
  width: 32em; height: 32em;
  border-radius: 50%;
  list-style: none;
}
.slice {
  overflow: hidden;
  position: absolute;
  top: 0; right: 0;
  width: 50%; height: 50%;
  transform-origin: 0% 100%; 
}
.slice:first-child {
  transform: rotate(15deg) skewY(-22.5deg);
}
.slice-contents {
  position: absolute;
  left: -100%;
  width: 200%; height: 200%;
  border-radius: 50%;
  background: lightblue;
}
.slice:first-child .slice-contents {
  transform: skewY(22.5deg); /* unskew slice contents */
}
.slice:hover .slice-contents { background: violet; } /* highlight on hover */

<ul class='pie'>
  <li class='slice'>
    <div class='slice-contents'></div>
  </li>
  <!-- you can add more slices here -->
<ul>

这篇关于使用CSS3的圈子中的细分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆