简体   繁体   English

有曲线的背景,可能吗?

[英]Background with curved line, Is it possible?

Should I spend a time to find a solution in CSS to apply it, or just added as a static background image. 我应该花点时间在CSS中找到一个解决方案来应用它,还是只是添加为静态背景图片?

I need to know if I can do something like in the attached image in CSS or not? 我需要知道是否可以在CSS的附加图片中进行操作吗? if yes how, please? 如果是,请如何?

曲线的抽象背景。

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. 我们可以使用SVGpath元素创建如上的形状,并用一些纯色,渐变或图案填充/描边。

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. QT命令用于绘制曲线。
  • V and H commands are used to draw straight lines. VH命令用于绘制直线。
  • 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM