Html 如何在css div中创建圆?

Html 如何在css div中创建圆?,html,css,Html,Css,代码: 但是,即使我在子divs元素上显示了:inline,在父元素上显示了100px的宽度和200px的高度,也不会显示任何内容,因此2个div都会进入底部?试试这种方法 .color-container { width: 100px; height: 200px; display: inline; position: relative; } .inline { display: inline; } #red { height: 50px; width: 50px;

代码:

但是,即使我在子divs元素上显示了:inline,在父元素上显示了100px的宽度和200px的高度,也不会显示任何内容,因此2个div都会进入底部?

试试这种方法

.color-container {
  width: 100px;
  height: 200px;
  display: inline;
  position: relative;
}
.inline {
  display: inline;
}
#red {
  height: 50px;
  width: 50px;
  background-color: red;
  border-radius: 50% 0 0 0;
}
#yellow {
  height: 50px;
  width: 50px;
  background-color: yellow;
  border-radius: 0 50% 0 0;
}
#green {
  height: 50px;
  width: 50px;
  background-color: green; 
  border-radius: 0 0 50% 0;
}
#blue {
  height: 50px;
  width: 50px;
  background-color: blue;
  border-radius: 0 0 0 50%;
}




您在任何地方都使用了className,这是错误的,它只是类,因此您需要更改:

<div class="color-container">
      <div class="inline" id="red"></div><div class="inline" id="green"></div><div class="inline" id="blue"></div><div class="inline" id="yellow"></div>
    </div>
    <br><br> <!-- Other Way-->
    <div class="color-container">
      <div class="inline" id="red"></div><!--
      --><div class="inline" id="green"></div><!--
      --><div class="inline" id="blue"></div><!--
      --><div class="inline" id="yellow"></div>
    </div>
不能设置宽度和高度,因为内联元素不能设置宽度和高度

相反,您需要使用显示:内联块:

display: inline;
但是,内联块有一个问题,即如果它们之间有空格,它们将在div之间添加一个间隙,因此需要像这样从html中删除所有空格:

.inline {
    display: inline;
}
}这是我的小提琴:

如果我理解正确的话。这是我的答案

.color容器{
宽度:100%;
高度:200px;
显示:内联块;
位置:相对位置;
}
#红色的{
高度:50px;
宽度:50px;
背景色:红色;
边界半径:50%50%50%50%;
显示:内联块;
}
#黄色的{
高度:50px;
宽度:50px;
背景颜色:黄色;
边界半径:50%50%50%50%;
显示:内联块;
}
#绿色的{
高度:50px;
宽度:50px;
背景颜色:绿色;
边界半径:50%50%50%50%;
显示:内联块;
}
#蓝色的{
高度:50px;
宽度:50px;
背景颜色:蓝色;
边界半径:50%50%50%50%;
显示:内联块;
}

试试这个:

#左{
宽度:50px;
高度:50px;
背景颜色:绿色;
显示:内联块;
边界半径:100%0
}
#对{
宽度:50px;
高度:50px;
背景色:红色;
显示:内联块;
边界半径:0 100%0 0
}
#左2{
宽度:50px;
高度:50px;
背景颜色:蓝色;
显示:内联块;
边界半径:0 100%
}
#对2{
宽度:50px;
高度:50px;
背景色:黑色;
显示:内联块;
边界半径:0 100%0
}


您想制作什么,是否可以附加任何所需结果的图像?可能的副本是否可以共享预期的输出图像。你到底在找什么。
<div class="color-container">
display: inline;
.inline {
    display: inline;
}
 <div class="color-container"><div class="inline" id="red"></div><div class="inline" id="green"></div><div class="inline" id="yellow"></div><div class="inline" id="blue"></div></div>
.circle {
    border-radius: 50%;
    width: 100px;
    height: 100px;