[英]Background with curved line, Is it possible?
SVG
is the recommended way to create such shapes. 推荐使用SVG
创建此类形状。 It offers simplicity and scale-ability. 它提供了简单性和可伸缩性。
We can use SVG
's path
element to create a shape like above and fill / stroke it with some solid color, gradient or a pattern. 我们可以使用SVG
的path
元素创建如上的形状,并用一些纯色,渐变或图案填充/描边。
Only one attribute d
is used to define shapes in path
element. 仅一个属性d
用于定义path
元素中的形状。 This attribute itself contains a number of short commands and few parameters that are necessary for those commands to work. 该属性本身包含许多短命令和少量参数,这些命令才起作用。
Following code will create the above shape: 以下代码将创建上述形状:
<path d="M-10,43
Q7,40 18,30
T42,41 T65,64 T92,32 T133,31 T167,17 T218,61
V240 H-180 Z" />
Below is a brief description of path
commands used in above code: 以下是上面代码中使用的path
命令的简要说明:
M
command is used to define the starting point. M
命令用于定义起点。 It appears at the beginning and specify the point from where drawing should start. 它出现在开始处,并指定应从其开始的点。 Q
and T
commands are used to draw curves. Q
和T
命令用于绘制曲线。 V
and H
commands are used to draw straight lines. V
和H
命令用于绘制直线。 Z
command is used to close current path. Z
命令用于关闭当前路径。 It draws a straight line from current point to the starting point to close the shape. 它从当前点到起点绘制一条直线以闭合形状。 Output Image: 输出图像:
Working Example: 工作示例:
body { text-align: center; background: #ddd; }
<svg width="175" height="230" viewBox="0 0 175 230" preserveAspectRatio="xMidYMin slice"> <defs> <linearGradient id="grad" x2="0" y2="1"> <stop offset="0" stop-color="#f5e2ed" /> <stop offset="1" stop-color="#fff" /> </linearGradient> </defs> <path stroke="#f280ab" stroke-width="3" fill="url('#grad')" d="M-10,43 Q7,40 18,30 T42,41 T65,64 T92,32 T133,31 T167,17 T218,61 V240 H-180 Z" /> </svg>
Useful Resources: 有用的资源:
Below are some useful links for SVG
: 以下是SVG
一些有用链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.