至少需要20px Border-radius才能获得圆形。在此图像中,我删除了边界 - 拉迪乌斯(Border-Radius),而SVG没有被剪裁。
我需要获得圆形的背景,而不会发生剪裁。
.tik-tok-icon {
fill: hsla(0, 0%, 50%, 1);
padding: 5px 7px;
background: hsla(0, 0%, 20%, 1);
border-radius: 40px;
padding: 10px 13px;
}
.icon {
height: 70px;
width: 70px;
}
<html>
<body>
<div class="icon">
<svg class="tik-tok-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" data-prefix="fab" data-icon="tiktok" class="1 _icon_1ijny5" viewBox="0 0 448 512"><path d="M448 209.91a210.06 210.06 0 01-122.77-39.25v178.72A162.55 162.55 0 11185 188.31v89.89a74.62 74.62 0 1052.23 71.18V0h88a121.18 121.18 0 001.86 22.17A122.18 122.18 0 00381 102.39a121.43 121.43 0 0067 20.14z"></path></svg>
</div>
</body>
</html>
是您想要圆形和背景颜色的包含的图标元素,并且可能带有一些填充。有多种定位SVG的方法。该片段使用Flex将其集中在图标元素中。它使用50%作为图标元素的边框半径来确保一个圆(无论您决定在图标元素上拥有什么尺寸和填充)。
<html>
<body>
<div class="icon">
<svg class="tik-tok-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" data-prefix="fab" data-icon="tiktok" class="1 _icon_1ijny5" viewBox="0 0 448 512"><path d="M448 209.91a210.06 210.06 0 01-122.77-39.25v178.72A162.55 162.55 0 11185 188.31v89.89a74.62 74.62 0 1052.23 71.18V0h88a121.18 121.18 0 001.86 22.17A122.18 122.18 0 00381 102.39a121.43 121.43 0 0067 20.14z"></path></svg>
</div>
</body>
</html>
As@ahoth
已经指出:最好将
border-radius
transform
.tik-tok-icon {
fill: hsla(0, 0%, 50%, 1);
transform: scale(0.6) translate(5%, -8%);
}
.icon {
background: hsla(0, 0%, 20%, 1);
height: 70px;
width: 70px;
border-radius: 50%;
}
其他方法是将图标svg的一个元素预先介绍:
<circle>
<svg class="tik-tok-icon2" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" data-prefix="fab" data-icon="tiktok" class="1 _icon_1ijny5" viewBox="0 0 512 512">
<circle class="icon-bg" cx="50%" cy="50%" r="50%" fill="#ccc" />
<path class="icon-path" transform-origin="center" transform="scale(0.7) translate(40, 0)" d="M448 209.91a210.06 210.06 0 01-122.77-39.25v178.72A162.55 162.55 0 11185 188.31v89.89a74.62 74.62 0 1052.23 71.18V0h88a121.18 121.18 0 001.86 22.17A122.18 122.18 0 00381 102.39a121.43 121.43 0 0067 20.14z" />
</svg>
.tik-tok-icon {
fill: hsla(0, 0%, 50%, 1);
transform: scale(0.6) translate(5%, -8%);
}
.icon {
background: hsla(0, 0%, 20%, 1);
height: 70px;
width: 70px;
border-radius: 50%;
}
.tik-tok-icon2 {
display: inline-block;
width: 70px;
}
.icon-bg {
fill: hsla(0, 0%, 20%, 1);
}
.icon-path {
fill: hsla(0, 0%, 50%, 1);
}
实际上,这是一个简单的技巧。在SVG元素上添加
<p>Border radius</p>
<div class="icon">
<svg class="tik-tok-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" data-prefix="fab" data-icon="tiktok" class="1 _icon_1ijny5" viewBox="0 0 448 512">
<path d="M448 209.91a210.06 210.06 0 01-122.77-39.25v178.72A162.55 162.55 0 11185 188.31v89.89a74.62 74.62 0 1052.23 71.18V0h88a121.18 121.18 0 001.86 22.17A122.18 122.18 0 00381 102.39a121.43 121.43 0 0067 20.14z" />
</svg>
</div>
<p>Circle bg in svg</p>
<svg class="tik-tok-icon2" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" data-prefix="fab" data-icon="tiktok" class="1 _icon_1ijny5" viewBox="0 0 512 512">
<circle class="icon-bg" cx="50%" cy="50%" r="50%" fill="#ccc" />
<path class="icon-path" transform-origin="center" transform="scale(0.7) translate(40, 0)" d="M448 209.91a210.06 210.06 0 01-122.77-39.25v178.72A162.55 162.55 0 11185 188.31v89.89a74.62 74.62 0 1052.23 71.18V0h88a121.18 121.18 0 001.86 22.17A122.18 122.18 0 00381 102.39a121.43 121.43 0 0067 20.14z" />
</svg>