css - 使用 css 用颜色部分填充 svg/png

标签 css html png

我是 CSS HTML 的新手。我正在尝试使用 CSS 进行跟踪。我有一个png图标。现在我想用颜色从下到上部分填充它,就像图像的链接一样。

enter image description here

最佳答案

您是否正在努力实现这样的目标? 我在你的 pin 中插入了一个 div(代表填充)并将 position 属性设置为 absolute。此外,我将表示引脚的父级 divposition 属性更改为 relative,现在您可以将填充绝对对齐,但在其父级内。

body,
html {
  height :100%;
}
body {
  background: #2F2F2F;
}
.pin {
  width:30px;
  height: 30px;
  border-radius: 50% 50% 50% 0;
  background: black;
  position: relative;
  transform: rotate(-45deg);
  left: 50%;
  top: 50%;
  margin: -20px 0 0 -20px;
}
.pin-fill {
  width :10px;
  height: 10px;
  background: yellow;
  position: absolute;
  border-radius: 50% 50% 50% 0;
  transform: rotate(1 deg);
  left: 0;
  bottom: 0;
}
<div class='pin'>
  <div class="pin-fill"></div>
</div>

编辑

如果你想让你的内部引脚 (.pin-fill) 看起来像一个填充物,我建议改变你的 border-radius 如下。

边界半径:0 100% 0 0;

片段

body,
html {
  height :100%;
}
body {
  background: #2F2F2F;
}
.pin {
  width:30px;
  height: 30px;
  border-radius: 50% 50% 50% 0;
  background: black;
  position: relative;
  transform: rotate(-45deg);
  left: 50%;
  top: 50%;
  margin: -20px 0 0 -20px;
}
.pin-fill {
  width :10px;
  height: 10px;
  background: yellow;
  position: absolute;
  border-radius: 0 100% 0 0;
  transform: rotate(1 deg);
  left: 0;
  bottom: 0;
}
<div class='pin'>
  <div class="pin-fill"></div>
</div>

这是一个普通填充的例子

body,
html {
  height: 100%;
}
body {
  background: #2F2F2F;
}
.pin {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 0;
  background: black;
  position: relative;
  transform: rotate(-45deg);
  left: 50%;
  top: 50%;
  margin: -20px 0 0 -20px;
}
.pin-fill {
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid yellow;
  position: absolute;
  left: -5px;
  bottom: 0px;
  transform: rotate(45deg);
}
<div class='pin'>
  <div class="pin-fill"></div>
</div>

关于css - 使用 css 用颜色部分填充 svg/png,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28128278/

相关文章:

php - 在没有 PHP 的情况下,如何在一页上的内容之间切换?

CSS、 Bootstrap 、HTML5

css - 未正确使用样式表

jquery - 将特定的 css 属性应用于子元素,同时将鼠标悬停在其前一个兄弟元素上

javascript - 将数组值移动到另一个特定数组

windows-7 - 通过Windows中的命令行工具合并两个png?

android - 如何将 View 从 Canvas 保存到 PNG 文件?

HTML/CSS 图像和文本格式问题(Bootstrap)

javascript - 如何使用标签取消选中jquery中的单选按钮

c - 如何从 PNG 文件中读取任意 block ?