html - 难以将蓝色变为透明
问题描述
如何将蓝色变为透明?https://jsfiddle.net/o64znkc5/
这就是我想要在代码中做的所有事情。
我怎么能做到这一点?
它要求我提供更多信息,但这就是一切。
我不知道该怎么做。
.exit {
top: auto;
bottom: -47.63px;
margin: auto;
right: 0;
left: 0;
width: 47.63px;
height: 47.63px;
cursor: pointer;
border: none;
background: none;
padding: 0;
border-radius: 50%;
clip-path: circle(50%);
}
.exit svg {
fill: red;
}
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<g id="exit">
<title>exit</title>
<path fill="red" d="m-101.116-101.116a143 143 0 11202.232 202.232a143 143 0 01-202.232-202.232zzzz" />
<circle cx="0" cy="0" r="113" />
<path fill="blue" d="m-101.116-101.116m169.705 11.313a113 113 0 00-137.178 0l68.589 68.59zm-158.392 21.214a113 113 0 000 137.178l68.59-68.589zm21.214 158.392a113 113 0 00137.178 0l-68.589-68.59zm158.392-21.214a113 113 0 000-137.178l-68.59 68.589z" />
</g>
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
解决方案
您现在拥有它的方式是不可能归档它,transparent
或者none
尽管您可以将它填充为白色作为背景。
.exit {
top: auto;
bottom: -47.63px;
margin: auto;
right: 0;
left: 0;
width: 47.63px;
height: 47.63px;
cursor: pointer;
border: none;
background: none;
padding: 0;
border-radius: 50%;
clip-path: circle(50%);
}
svg,use{fill:blue}
button:hover svg,
button:hover use
{fill:white}
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<g id="exit">
<title>exit</title>
<path fill="red" d="m-101.116-101.116a143 143 0 11202.232 202.232a143 143 0 01-202.232-202.232zzzz" />
<circle cx="0" cy="0" r="113" fill="red" />
<path d="m-101.116-101.116m169.705 11.313a113 113 0 00-137.178 0l68.589 68.59zm-158.392 21.214a113 113 0 000 137.178l68.59-68.589zm21.214 158.392a113 113 0 00137.178 0l-68.589-68.59zm158.392-21.214a113 113 0 000-137.178l-68.59 68.589z" />
</g>
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
但是,如果您需要它是透明的,我会像这样更改代码:我正在使用由两条路径制成的蒙版来刺穿红色底座。请注意,在面具中,应该是一个洞的地方被填充为白色,而可见部分则保持黑色。
.exit {
top: auto;
bottom: -47.63px;
margin: auto;
right: 0;
left: 0;
width: 47.63px;
height: 47.63px;
cursor: pointer;
border: none;
background: none;
padding: 0;
border-radius: 50%;
clip-path: circle(50%);
}
svg,use{fill:blue}
button:hover svg,
button:hover use
{fill:none}
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<g id="exit">
<title>exit</title>
<circle cx="0" cy="0" r="113" />
<path fill="red" mask="url(#m)" d="m-101.116-101.116a143 143 0 11202.232 202.232a143 143 0 01-202.232-202.232zzzz" />
<mask id="m">
<path fill="white" d="m-101.116-101.116a143 143 0 11202.232 202.232a143 143 0 01-202.232-202.232zzzz" />
<path fill="black" d="m-101.116-101.116m169.705 11.313a113 113 0 00-137.178 0l68.589 68.59zm-158.392 21.214a113 113 0 000 137.178l68.59-68.589zm21.214 158.392a113 113 0 00137.178 0l-68.589-68.59zm158.392-21.214a113 113 0 000-137.178l-68.59 68.589z" />
</mask>
</g>
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg width="100%" height="100%" viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
另一个观察:为了保持一致性,我将只使用<use>
按钮内的元素,方法是使 svg 元素不可见, width="0" height="0" 和 position:absolute;
此外,您不需要按钮内的 svg 元素内的 width="100%" 。默认情况下,它们将是 100% 宽
.exit {
top: auto;
bottom: -47.63px;
margin: auto;
right: 0;
left: 0;
width: 47.63px;
height: 47.63px;
cursor: pointer;
border: none;
background: none;
padding: 0;
border-radius: 50%;
clip-path: circle(50%);
}
svg[width = "0"]{
position:absolute;
left:-100em;}
use{fill:blue}
button:hover use
{fill:none}
<svg width="0" height="0">
<g id="exit">
<title>exit</title>
<circle cx="0" cy="0" r="113" />
<path fill="red" mask="url(#m)" d="m-101.116-101.116a143 143 0 11202.232 202.232a143 143 0 01-202.232-202.232zzzz" />
<mask id="m">
<path fill="white" d="m-101.116-101.116a143 143 0 11202.232 202.232a143 143 0 01-202.232-202.232zzzz" />
<path fill="black" d="m-101.116-101.116m169.705 11.313a113 113 0 00-137.178 0l68.589 68.59zm-158.392 21.214a113 113 0 000 137.178l68.59-68.589zm21.214 158.392a113 113 0 00137.178 0l-68.589-68.59zm158.392-21.214a113 113 0 000-137.178l-68.59 68.589z" />
</mask>
</g>
</svg>
<button class="exit" type="button" aria-label="Close">
<svg viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<!--You can add as many buttons you want using rhe same structure-->
<button class="exit" type="button" aria-label="Close">
<svg viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
<button class="exit" type="button" aria-label="Close">
<svg viewBox="-144 -144 288 288">
<use href="#exit" />
</svg>
</button>
推荐阅读
- javascript - 使用时间表时,Laravel 验证似乎不起作用
- javascript - 带有索引范围的 js 字符串 .replace() 方法
- reactjs - 使用 react 和 typescript 从 docker 容器中获取环境变量
- jquery - 使用 simplewebrtc 的 Firefox 中的跨域请求被阻止错误
- office-js - 如何使用 Office JavaScript API 确保 Excel Online 请求小于 5MB
- ruby-on-rails - 如何从rails在filepond中显示上传的图像
- sql - Ruby On Rails:如何在单个 SQL 查询中选择父模型的所有子模型以及这些子模型的 Active Storage 附件。活动记录
- c - 编写一个函数,对两个数 a 和 b 使用指针返回它们的平方和 a ^ 2 + b ^ 2 和 (a + b) ^ 2
- python - 当我测试 api 它显示方法不允许错误
- android - 如何在 kotlin 中将保留注释与 RetentionPolicy 一起使用