如何使用CSS在另一个内部制作一个圆圈

sca*_*t17 15 css css3

我正在尝试使用css在另一个圆圈内创建一个圆圈,但我有一个问题使它完全居中.我很亲密,但仍然没有.有任何想法吗?

<div id="content">
    <h1>Test Circle</h1>
    <div id="outer-circle">
        <div id="inner-circle">
            <span id="inside-content"></span>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

这是我的CSS:

#outer-circle {
    background: #385a94;
    border-radius: 50%;
    height:500px;
    width:500px;
}
#inner-circle {
    position: relative;
    background: #a9aaab;
    border-radius: 50%;
    height:300px;
    width:300px;
    margin: 0px 0px 0px 100px;
}
Run Code Online (Sandbox Code Playgroud)

另外,这里有一个小提琴:http: //jsfiddle.net/972SF/

mis*_*Sam 30

塔达!

在CSS评论中解释:

 #outer-circle {
   background: #385a94;
   border-radius: 50%;
   height: 500px;
   width: 500px;
   position: relative;
   /* 
    Child elements with absolute positioning will be 
    positioned relative to this div 
   */
 }
 #inner-circle {
   position: absolute;
   background: #a9aaab;
   border-radius: 50%;
   height: 300px;
   width: 300px;
   /*
    Put top edge and left edge in the center
   */
   top: 50%;
   left: 50%;
   margin: -150px 0px 0px -150px;
   /* 
    Offset the position correctly with
    minus half of the width and minus half of the height 
   */
 }
Run Code Online (Sandbox Code Playgroud)
<div id="outer-circle">
  <div id="inner-circle">

  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

  • 就像魔法一样!哈哈。谢谢。一旦允许,我将立即将您标记为答案! (2认同)

Pau*_*e_D 19

你不需要CSS3中的额外元素

你可以使用一个元素和一个box-shadow来完成所有操作.

JSFiddle演示.

CSS

#outer-circle {
    background: #385a94;
    border-radius: 50%;
    height:300px;
    width:300px;
    position: relative;
    box-shadow: 0 0 0 100px black;
    margin:100px;
}
Run Code Online (Sandbox Code Playgroud)


小智 14

如果你只想用一个div来添加圆内圆,那么使用box-shadow。

div {
  border-radius: 50%;
  box-shadow: 0px 0px 0px 10px red, 0px 0px 0px 20px green, 0px 0px 0px 30px yellow, 0px 0px 0px 40px pink;
  width: 100px;
  height:100px;
  margin: 3em;
}
Run Code Online (Sandbox Code Playgroud)
<div></div>
Run Code Online (Sandbox Code Playgroud)

  • 很好,这是我认为仅使用一个 div 的最佳解决方案。 (4认同)

小智 5

通过使用 CSS 变换属性解决了这个问题:

您可以参考JS fiddle link以下输出: http://jsfiddle.net/suprabhasupi/74b1ptne/ 圈内圈

div {
  border-radius: 50%;
  /* border: 1px solid red; */
}

.circle1 {
  position: relative;
  width: 300px;
  height: 300px;
  background-color: red;
}

.circle2 {
  transform: translate(25%, 25%);
  width: 200px;
  height: 200px;
  background-color: green;
}

.circle3 {
   transform: translate(48%, 46%);
  width: 100px;
  height: 100px;
  background-color: blue;
}
Run Code Online (Sandbox Code Playgroud)
<div class="circle1">
  <div class="circle2">
    <div class="circle3">
    
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)