如何在圆形图像上设置这个三角形? [英] How to style this triangle on a circular image?
问题描述
我在我的项目中使用bootstrap 3.3,我想使用CSS风格的照片。请指导我如何做到这一点?
I am using bootstrap 3.3 in my project, I would like to style the photo using CSS. please guide me how can to do this?
预览(我需要的):
推荐答案
您可以使用 svg
的 clipPath
和过滤器$ c $
box-shadow
。
You can do this using svg
's clipPath
and filter
s for the box-shadow
.
使用用于圆上坐标的公式计算三角形的坐标:
The co-ordinates for the triangle were calculated using the formula for a co-ordinate on a circle:
(x,y)= (θ),r×sin(θ))
其中, r
是圆的半径, code>是角度。
(x, y) = (r × cos(θ), r × sin(θ))
where, r
is the radius of a circle and θ
is the angle.
不在圆上的坐标假定为半径<$ c的圆上的坐标$ c> 55px ,比原始圆圈的半径( 50px
)小 5px
。
The co-ordinate that is not on the circle was assumed to be a co-ordinate on a circle with radius 55px
, which is 5px
more than the original circle's radius(50px
).
(x1, y1) = (ra × cos(θ), ra × sin(θ))
= (50px × cos(30°), 50px × sin(30°))
= (43.30px, 25px)
(a1, b1) = (rb × cos(θ), rb × sin(θ))
= (55px × cos(40°), 55px × sin(40°))
= (42.13px, 35.35px)
(x2, y2) = (ra × cos(θ), ra × sin(θ))
= (50px × cos(50°), 50px × sin(50°))
= (32.14px, 38.30px)
######################################################################################################
## ##
## At this point, these co-ordinates' origin is the center of the circle, but we need it to be the ##
## top left corner, so we add the radius of the circle to the co-ordinates as well. ##
## ##
######################################################################################################
(ra + x1, ra + y1) = (50px + 43.30px, 50px + 25px) = (93.30px, 75px)
(rb + a1, rb + b1) = (55px + 42.13px, 55px + 35.35px) = (97.13px, 90.35px)
(ra + x2, ra + y2) = (50px + 32.14px, 50px + 38.30px) = (82.14px, 88.30px)
坐标(93.30px,75px)
,(97.13px,90.35px)
和 (82.14px,88.30px)
与 M93,75 L97,90 L82,88
。
所以,这是我计算坐标。
So, that's how I calculated the co-ordinates.
<svg width="125" height="120" viewBox="-12 -8 124 124">
<defs>
<clipPath id="shape">
<path d="M50,50 m-50,0 a50,50 0 0,0 82,38 M93,75 L97,90 L82,88 M0,50 a50,50 0 1,1 93,25z M0,50 L93,75 L82,88z" />
</clipPath>
<filter id="boxshadow" width="140%" height="140%">
<feGaussianBlur in="SourceAlpha" stdDeviation="6" />
<feOffset dx="0" dy="5" result="offsetblur" />
<feMerge>
<feMergeNode/>
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</defs>
<path filter="url(#boxshadow)" d="M50,50 m-50,0 a50,50 0 0,0 82,38 M93,75 L97,90 L82,88 M0,50 a50,50 0 1,1 93,25" fill="none" stroke="#F3FEF8" stroke-width="5" stroke-miterlimit="4" stroke-linejoin="round" stroke-linecap="round" />
<image clip-path="url(#shape)" xlink:href="http://www.lorempixel.com/100/100" width="100" height="100" x="0" y="0" />
</svg>
clipPath
和 filter
位于 defs
标签中,这意味着您正在定义它们,如果您希望使用它们,则只需要定义一次
The clipPath
and filter
are in defs
tags, which means you are defining them and they only need to be defined once if you wish to use them multiple times on your page.
此外,路径
元素与 id =border
对于相同的图片大小总是相同的,并在页面上重复使用它,您可以使用使用
标记, path
元素如下:
Also, the path
element with id="border"
is always going to be same for identical image sizes and to re-use it on the page you could use the use
tag giving it a reference of the original path
element like so:
<use xlink:href="#border" />
因此,您不必重复相同的路径
元素每次添加边框。
So, you don't have to repeat the same path
element everytime you add a border.
<svg width="0" height="0">
<defs>
<clipPath id="shape">
<path d="M50,50 m-50,0 a50,50 0 0,0 82,38 M93,75 L97,90 L82,88 M0,50 a50,50 0 1,1 93,25z M0,50 L93,75 L82,88z" />
</clipPath>
<filter id="boxshadow" width="140%" height="140%">
<feGaussianBlur in="SourceAlpha" stdDeviation="6" />
<feOffset dx="0" dy="5" result="offsetblur" />
<feMerge>
<feMergeNode/>
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</defs>
</svg>
<svg width="125" height="120" viewBox="-12 -8 124 124">
<path id="border" filter="url(#boxshadow)" d="M50,50 m-50,0 a50,50 0 0,0 82,38 M93,75 L97,90 L82,88 M0,50 a50,50 0 1,1 93,25" fill="none" stroke="#F3FEF8" stroke-width="5" stroke-miterlimit="4" stroke-linejoin="round" stroke-linecap="round" />
<image clip-path="url(#shape)" xlink:href="http://www.lorempixel.com/100/100" width="100" height="100" x="0" y="0" />
</svg>
<svg width="125" height="120" viewBox="-12 -8 124 124">
<use xlink:href="#border" />
<image clip-path="url(#shape)" xlink:href="http://www.lorempixel.com/100/100" width="100" height="100" x="0" y="0" />
</svg>
<svg width="125" height="120" viewBox="-12 -8 124 124">
<use xlink:href="#border" />
<image clip-path="url(#shape)" xlink:href="http://www.lorempixel.com/100/100" width="100" height="100" x="0" y="0" />
</svg>
<svg width="125" height="120" viewBox="-12 -8 124 124">
<use xlink:href="#border" />
<image clip-path="url(#shape)" xlink:href="http://www.lorempixel.com/100/100" width="100" height="100" x="0" y="0" />
</svg>
<svg width="125" height="120" viewBox="-12 -8 124 124">
<use xlink:href="#border" />
<image clip-path="url(#shape)" xlink:href="http://www.lorempixel.com/100/100" width="100" height="100" x="0" y="0" />
</svg>
<svg width="125" height="120" viewBox="-12 -8 124 124">
<use xlink:href="#border" />
<image clip-path="url(#shape)" xlink:href="http://www.lorempixel.com/100/100" width="100" height="100" x="0" y="0" />
</svg>
<svg width="125" height="120" viewBox="-12 -8 124 124">
<use xlink:href="#border" />
<image clip-path="url(#shape)" xlink:href="http://www.lorempixel.com/100/100" width="100" height="100" x="0" y="0" />
</svg>
<svg width="125" height="120" viewBox="-12 -8 124 124">
<use xlink:href="#border" />
<image clip-path="url(#shape)" xlink:href="http://www.lorempixel.com/100/100" width="100" height="100" x="0" y="0" />
</svg>
这篇关于如何在圆形图像上设置这个三角形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!