简体   繁体   English

是否可以在圆圈周围放置物品?

[英]Is it possible to position items around the circle?

I am trying to make a circle and put 3 equals part around it. 我正在尝试制作一个圆圈并在其周围放置3个相等的部分。 I saw the image below in the site, but I want three equals part and not four. 我在网站上看到了下面的图片,但我想要三个等于一部分,而不是四个。

I want them (the parts) to be like a button. 我希望它们(部件)就像一个按钮。 If someone click them they will refer to another page. 如果有人点击它们,他们将引用另一页。

圆圈图像

I tried a lot but without success. 我尝试了很多但没有成功。 My goal is that each button around the circle will refer to another page. 我的目标是圈子周围的每个按钮都会引用另一个页面。 Is it possible to do it just with HTML and CSS? 是否可以使用HTML和CSS来实现? and if yes, how? 如果是,怎么样?

Using CSS: 使用CSS:

One pure CSS way to create this shape would be to use CSS skew transforms. 创建此形状的一种纯CSS方法是使用CSS skew变换。 Since you need click events on the parts, it is better to use separate elements instead of using pseudo-elements. 由于您需要在零件上单击事件,因此最好使用单独的元素而不是使用伪元素。

 .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> 


Using SVG: 使用SVG:

I would still recommend using SVG for creating such shapes because it allows for better control over the circle and its parts. 我仍然建议使用SVG来创建这样的形状,因为它可以更好地控制圆形及其部分。 The co-ordinates for the path should be set by identifying points on the circle. 应通过识别圆上的点来设置路径的坐标。 The logic to identify the points on a circle is described in my answer here . 我在这里的答案中描述了识别圆上点的逻辑。 It uses trigonometry. 它使用三角法。

 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> 

okay, from a list you could use absolute + trasform: DEMO 好的,从列表中你可以使用absolute + trasform: DEMO

 ul, li { margin: 0; padding: 0; list-style-type: none; display: block; box-sizing: border-box; overflow: hidden; } ul { margin: 1em auto; height: 300px; width: 300px; border: solid; border-radius: 50%; transform: rotate(45deg); background: #1D69A3; } li a { box-shadow: 0 0 5px; height: 100%; width: 100%; margin: -50%; position: absolute; background: tomato; top: 0; left: 0; transform-origin: bottom right; transform: rotate(0deg) skew(-15deg, -15deg); } li:nth-child(2) a { transform-origin: bottom left; transform: rotate(30deg) skew(15deg, 15deg); background: turquoise; top: 0; left: 100%; } li:nth-child(3) a { transform-origin: top right; top: auto; left: 0; bottom: 0; transform: rotate(-30deg) skew(15deg, 15deg); background: #7F9A12 } /* hide center ? */ ul:before { content: ''; position: absolute; top: 25%; left: 25%; right: 25%; bottom: 25%; background: purple; z-index: 1; border-radius: 50%; box-shadow: 0 0 5px, inset 15px 5px 15px 5px rgba(255, 255, 255, 0.2); border: solid 1px; } /* see some effects on hover */ a:hover { mix-blend-mode: multiply } ul:hover:before { mix-blend-mode:color } 
 <ul> <li><a href="#"><b>item 1</b></a></li><!-- <b> is here if you wish to add text and style in order to show it --> <li><a href="#"><b>item 2</b></a></li> <li><a href="#"><b>item 3</b></a></li> </ul> 

u can use border-radius, create four divs with border-radius 50% and one div with 100% border radius in center for your content 你可以使用border-radius,创建四个边框半径为50%的div和一个内部边界半径为100%的div用于你的内容

<div class="container">
<div class="around top-left">
</div>
<div class="around top-right">
</div>
<div class="around bottom-left">
</div>
<div class="around bottom-right">
</div>
<div class="content">
</div>
</div>

CSS: CSS:

.container{
  position:relative;
  width:200px;
  height:200px;
}
.content{
  width:50%;
  height:50%;
  left:50px;
  top:50px;
  position:absolute;
  background-color:white;
  z-index:1;
  border-radius:50%;
}
.around{
  background-color:red;
  width:100px;
  height:100px;
  display:inline-block;
  position:absolute;
}
.top-left{border-top-left-radius:100%; top:0; left:0; background:blue;}
.top-right{border-top-right-radius:100%; top:0; right:0;background:green;}
.bottom-left{border-bottom-left-radius:100%; bottom:0; left:0;background:orange;}
.bottom-right{border-bottom-right-radius:100%; bottom:0; right:0;background:purple;}

JSFiddle 的jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM