8

I'm trying to create a ring shape in css, divided into 4 quarters. Each quarter will represent a button.

I've been playing around with the following code:

#quarterCircleTopLeft{
     width:100px;
     height:100px;
     border:1px solid #000;
     background: orange;
     border-radius: 90px 0 70px 0;
     -moz-border-radius: 90px 0 70px 0;
     -webkit-border-radius: 90px 0 70px 0;
}

Which produces this (disregard the grey lines):

enter image description here

Obviously, I want the border at the right bottom to be inverted. However, since this is a button I cannot use another shape to produce a cutout (as this would overlap with other buttons of the menu). I've added a red line to show approx how I would want the border to go. Sorry, my paint skills are bad :-P

How can I invert the border or in another way produce the shape I want?

4

4 回答 4

12

我会做类似的事情:

http://dabblet.com/gist/5476973

简而言之,很多边界半径+所有东西顶部的白色圆圈。

在我的示例中,然后我将使用 javascript 将点击事件绑定到 div,或者只是将它们设为所有<a>元素并添加一个display:block;.

/**
* Quarter Circles
*/

.main {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto;
}
.quarter {
  position: absolute;
  width: 50%;
  height: 50%;
  transition: background-color 0.2s ease-in-out;
}
.quarter:hover {
  background-color: pink;
}
.quarter1 {
  top: 0;
  left: 0;
  background-color: red;
  border-radius: 100% 0 0 0;
}
.quarter2 {
  top: 0;
  right: 0;
  background-color: blue;
  border-radius: 0 100% 0 0;
}
.quarter3 {
  bottom: 0;
  left: 0;
  background-color: orange;
  border-radius: 0 0 0 100%;
}
.quarter4 {
  bottom: 0;
  right: 0;
  background-color: green;
  border-radius: 0 0 100% 0;
}
.cutout {
  width: 50%;
  height: 50%;
  background-color: white;
  position: absolute;
  top: 25%;
  left: 25%;
  border-radius: 50%;
  pointer-events: none;
}
<div class="main">
  <div class="quarter quarter1"></div>
  <div class="quarter quarter2"></div>
  <div class="quarter quarter3"></div>
  <div class="quarter quarter4"></div>
  <div class="cutout"></div>
</div>

于 2013-04-28T14:03:06.063 回答
2

这是一个 <svg> 解决方案。

svg 有自己的 <a> 元素 svg。
只需按下角落,您就会发现一些令人惊叹的文档;)
笑话放在一边 a 链接适用于形状,因此形状获取链接。
这会在形状内部留下空间空白空间,以显示其后面的任何东西。

<svg width="150px" height="150px" viewbox="-1 -1 102 102">
  <a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
    <path stroke="tomato" fill="orange" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20 
                                         C 31 20 20 31 20 50Z" />
  </a>
  <a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
    <path stroke="darkRed" fill="red" transform="translate(100, 0) rotate(90)" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20 
                                         C 31 20 20 31 20 50Z" />
  </a>
  <a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
    <path stroke="DarkBlue" fill="blue" transform="translate(100, 100) rotate(180)" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20 
                                         C 31 20 20 31 20 50Z" />
  </a>
  <a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
    <path stroke="darkGreen" href="#" fill="green" transform="translate(0, 100) rotate(-90)" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20 
                                         C 31 20 20 31 20 50Z" />
  </a>
</svg>

于 2015-05-08T14:36:39.053 回答
1

当鼠标位于截止区域时,我已经能够增强第一个答案并避免响铃响应。

http://codepen.io/a-zaki/pen/rLRyAm

/**
* Quarter Circles
*/

.main {
  position: relative;
  width: 300px;
  height: 300px;
  margin: 0 auto;
}
.quarter {
  position: absolute;
  width: 50%;
  height: 50%;
  transition: background-color 0.2s ease-in-out;
  z-index: 1;
}
.quarter:hover {
  background-color: pink;
}
.quarter1 {
  top: 0;
  left: 0;
  background-color: red;
  border-radius: 100% 0 0 0;
}
.quarter2 {
  top: 0;
  right: 0;
  background-color: blue;
  border-radius: 0 100% 0 0;
}
.quarter3 {
  bottom: 0;
  left: 0;
  background-color: orange;
  border-radius: 0 0 0 100%;
}
.quarter4 {
  bottom: 0;
  right: 0;
  background-color: green;
  border-radius: 0 0 100% 0;
}
.cutout {
  width: 50%;
  height: 50%;
  background-color: white;
  position: absolute;
  top: 25%;
  left: 25%;
  border-radius: 50%;
  border: 3px solid #000;
  z-index: 2;
}
<div class="main">
  <div class="quarter quarter1"></div>
  <div class="quarter quarter2"></div>
  <div class="quarter quarter3"></div>
  <div class="quarter quarter4"></div>
  <div class="cutout"></div>
</div>

于 2016-11-02T14:00:25.413 回答
0

在 Safari 上,这应该可以工作:

<!DOCTYPE html>
<html>
<head>
<style> 
  div {
    width: 40px;
    height: 40px;
    border: solid;
    border-radius: 100px 0 0 0;
    border-width: 30px 30px 0;
    border-right: hidden;
  }
</style>
<title>Quatre Circle Outline</title>
</head>
<body>
    <div></div>
</body>
</html>
于 2021-02-19T21:55:18.637 回答