html - 是否可以将元素放置在圆圈周围?

标签 html css css-shapes

我正在尝试制作一个圆圈并在其周围放置 3 个相等的部分。 我在网站上看到了下面的图片,但我想要三个相等的部分而不是四个。

我希望它们(部件)像一个按钮。如果有人点击它们,他们将指向另一个页面。

circle image

我尝试了很多,但都没有成功。我的目标是圆圈周围的每个按钮都指向另一个页面。是否可以仅使用 HTML 和 CSS 来实现?如果是,怎么办?

最佳答案

使用 CSS:

创建此形状的一种纯 CSS 方法是使用 CSS skew 变换。由于您需要在部件上单击事件,因此最好使用单独的元素而不是使用伪元素。

.outer {
  position: relative;
  height: 200px;
  width: 200px;
  border-radius: 50%;
  border: 2px solid;
  overflow: hidden;
}
.inner {
  position: absolute;
  height: 50%;
  width: 50%;
  top: calc(25% - 2px);
  left: calc(25% - 2px);
  border-radius: 50%;
  background: yellowgreen;
  border: 2px solid;
}
.part {
  position: absolute;
  height: 100%;
  width: 100%;
}
.part:nth-child(2) {
  top: -50%;
  left: calc(-50% - 2px);
  transform: skewY(-30deg);
  transform-origin: right bottom;
  background: red;
  border: 2px solid;  
}
.part:nth-child(3) {
  top: -50%;
  right: calc(-50% - 2px);
  transform: skewY(30deg);
  transform-origin: left bottom;
  background: green;
  border: 2px solid;
}
.part:nth-child(1) {
  top: 0%;
  left: 0%;
  width: 100%;
  background: yellow;
}
.part:hover {
  background: chocolate;
}
.part:nth-child(1) p{
  position: absolute;
  top: 85%;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
}
.part:nth-child(2) p{
  position: absolute;
  top: 50%;
  left: 55%;
  transform: skewY(30deg);
}
.part:nth-child(3) p{
  position: absolute;
  top: 50%;
  left: 30%;
  transform: skewY(-30deg);
}
<div class='outer'>
  <div class='part'><p>Text</p></div>
  <div class='part'><p>Text</p></div>
  <div class='part'><p>Text</p></div>
  <div class='inner'></div>
</div>


使用 SVG:

我仍然会推荐使用 SVG 来创建这样的形状,因为它可以更好地控制圆及其部分。路径的坐标应通过识别圆上的点来设置。 my answer here 中描述了识别圆上点的逻辑。 .它使用三 Angular 函数。

svg {
  height: 30vw;
  width: 30vw;
}
svg circle {
  fill: transparent;
  stroke: black;
}
path {
  stroke: black;
}
#part1 {
  fill: green;
}
#part2 {
  fill: yellow;
}
#part3 {
  fill: red;
}
#inner {
  fill: yellowgreen;
}
#part1:hover,
#part2:hover,
#part3:hover {
  fill: chocolate;
}
<svg viewBox='0 0 100 100'>
  <defs>
    <path d='M13.63,71 A42,42 0 0,1 50,8' id='path1' />
    <path d='M50,8 A42,42 0 0,1 86.37,71' id='path2' />
    <path d='M13.63,76 A42,42 0 0,0 86.37,76' id='path3' />
  </defs>

  <path d='M50,0 A50,50 0 0,0 7,75 L50,50z' id='part1' />  <!-- should use trignometry to calculate points - angle = 30deg -->
  <path d='M50,0 A50,50 0 0,1 93,75 L50,50z' id='part2' />  <!-- should use trignometry to calculate points - angle = 300deg -->
  <path d='M7,75 A50,50 0 0,0 93,75 L50,50z' id='part3' />  <!-- should use points calculated for previous two paths -->
  <circle cx='50' cy='50' r='40' id='inner' />
  
  <text font-family="Calibri" font-size="8" x="28">
    <textPath xlink:href="#path1">
      Tab 1 Text
    </textPath>
  </text>
  <text font-family="Calibri" font-size="8" x="28">
    <textPath xlink:href="#path2">
      Tab 2 Text
    </textPath>
  </text>  
  <text font-family="Calibri" font-size="8" x="28">
    <textPath xlink:href="#path3">
      Tab 3 Text
    </textPath>
  </text>  
</svg>

关于html - 是否可以将元素放置在圆圈周围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34827096/

相关文章:

javascript - jQuery 的 .css() 实现

css - 从无显示切换到显示 block 时,Emberjs 组件操作未触发

html - 已 float 的中心图标

html - CSS?这个箭头是怎么做出来的?

html - 如何创建一个偏向一侧的div

java - Dom命名空间问题

android - 当前在 Android 上支持使用 html5 音频标签一次播放多个音轨

html - 在 Gmail HTML 电子邮件中隐藏内容 - 但在移动设备中显示?

jquery - 不透明度为 1 到 0 的动画剪辑 jq​​uery 效果

css - 如何在CSS中创建一个对话泡泡?