【问题标题】:How to create a 3d shape with a bend [closed]如何创建带有弯曲的 3d 形状 [关闭]
【发布时间】:2015-10-12 21:58:28
【问题描述】:

我希望能够创建一个类似于钹的 3d 形状。 Here 是我想要的弯的链接。但我希望它有一个 xy 轴。

这是我开始使用的基本 css:

div{
  width:300px; height:300px;  
  border:solid 5px #000;
  border-color:#000 transparent transparent transparent;
  border-radius: 50%/300px 300px 0 0;
  background-color:#FF0000;
}

使用上面的代码。它只会创建一个弯曲的边框。我需要改变自己变成一个形状。

解决方案的一个例子是提取下面例子的黑色区域,点击“眼睛”:here

如何使用纯 CSS 来创建它?我研究了可能有助于实现这一点的贝塞尔曲线和外部 JS 函数。

有人看到/有解决这个问题的方法吗?谢谢。

【问题讨论】:

  • @Paulie_D 给我一个机会:P 更新了!感谢 cmets
  • 使用 SVG 将是我的答案,但目前还不清楚您要做什么。
  • @Paulie_D 我想使用 CSS 创建一个 3d 对象。想想鼓钹或球体的外层。但它仍然有 x、y 和 z 轴。
  • 是符号吗?我虽然是一只眼睛。
  • 如果删除空格。它实际上是一个钹。 @GolezTrol

标签: css 3d css-shapes bezier


【解决方案1】:

您无法真正在 css 或 svg 中创建适当的 3D 形状,因为它们在 2D 平面上运行。

但您可以创建许多 2d 平面使其看起来像 3D:

body {
  background-color: black
}
.wrapper {
  perspective: 500px;
  width: 200px;
  height: 200px;
}
.wrapper .cymbal {
  top: 175px;
  left: 175px;
  position: absolute;
  transform-style: preserve-3d;
  transform: rotateY(180deg) rotateX(90deg);
  transition: transform 2s;
}
.wrapper:hover .cymbal {
  transform: rotateY(0deg) rotateX(0deg);
}
.wrapper .cymbal div {
  position: absolute;
  border-radius: 50%;
  background-color: gold;
  border: 1px solid black;
}
.wrapper .cymbal div:nth-of-type(1) {
  width: 10px;
  height: 10px;
  transform: translateZ(20px) translate(-50%, -50%);
}
.wrapper .cymbal div:nth-of-type(2) {
  width: 15px;
  height: 15px;
  transform: translateZ(15px) translate(-50%, -50%);
}
.wrapper .cymbal div:nth-of-type(3) {
  width: 20px;
  height: 20px;
  transform: translateZ(10px) translate(-50%, -50%);
}
.wrapper .cymbal div:nth-of-type(4) {
  width: 30px;
  height: 30px;
  transform: translateZ(5px) translate(-50%, -50%);
}
.wrapper .cymbal div:nth-of-type(5) {
  width: 35px;
  height: 35px;
  transform: translateZ(0px) translate(-50%, -50%);
}
.wrapper .cymbal div:nth-of-type(6) {
  width: 56px;
  height: 56px;
  transform: translateZ(-5px) translate(-50%, -50%);
}
.wrapper .cymbal div:nth-of-type(7) {
  width: 80px;
  height: 80px;
  transform: translateZ(-10px) translate(-50%, -50%);
}
<div class="wrapper">
  <div class="cymbal">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>
</div>

【讨论】:

  • 这是最合适的。在这种情况下,使用 2d 形状使用图层制作整体 3d 对象&lt;div&gt;'s。我将尝试执行此操作!感谢您的回答!
  • 人们甚至可以争辩说,计算机图形学中的所有“3d”形状都是由“平面”三角形组成的……;)
  • @m01 你说得对,先生。
【解决方案2】:

CSS 变换

可以使用 CSS 转换创建 cymbal shape,更具体地说是 perspective 转换。

要使其更加 3d,需要多个元素或使用浏览器特定的属性来获得关闭效果。

div {
  width: 200px;
  height: 200px;
  border: 1px solid black;
  border-radius: 50%;
  transform: perspective(400px) rotateX(50deg);
  background: radial-gradient(ellipse at center, #000000 1%, #fceabb 2%, #fccd4d 30%, #f8b500 31%, #fbdf93 100%);
  margin: 20px;
}
&lt;div&gt;&lt;/div&gt;

【讨论】:

  • 这看起来像是解决方案。将通过操纵视角来测试它。不过非常感谢您的回答!
  • 但是看代码。看起来它不利于最初出现问题的弯曲。
  • 你不能在 CSS 中“弯曲”。 CSS 有 3d 变换,但它没有创建 3d 样式元素的能力。
猜你喜欢
  • 2015-05-05
  • 1970-01-01
  • 1970-01-01
  • 2021-11-19
  • 2020-01-06
  • 1970-01-01
  • 2021-05-14
  • 1970-01-01
  • 2021-11-12
相关资源
最近更新 更多