前端入门:HTML(SVG)

一、预定义的形状元素

矩形:rect 圆形:cicle 椭圆:ellipse 线条:line 多线条:polyline 多边形:polygon 路径:path

1.绘制矩形

案例:

源代码:

 <!-- 矩形 -->

    <svg width="400" height="110">

        <rect width="300" height="100" fill="pink" stroke-width="3" stroke="black"/>

    </svg>

    <br>

    <!-- 设置不透明度 -->

    <svg width="400" height="180">

        <rect x="50" y="20" width="150" height="150" fill="pink" stroke="tomato"

        stroke-width="5" opacity="0.5" />

    </svg>

    <br>

<!-- 圆角矩形 -->

    <svg width="400" height="180">

        <rect x="50" y="20" width="150" height="150" fill="pink" stroke="tomato"

        stroke-width="5" opacity="0.5" rx="20" ry="20"/>

    </svg>

    <br>

2.绘制圆形

案例:

源代码:

<!-- 圆形 -->

    <svg width="100" height="100">

        <circle cx="50" cy="50" r="40" fill="pink" stroke="tomato" stroke-width="3" />

    </svg>

    <br>

3.绘制椭圆形

案例:

源代码:

 <!-- 椭圆形 -->

    <svg width="500" height="140">

        <ellipse cx="200" cy="80" rx="100" ry="50" fill="pink" stroke="tomato" stroke-width="2" />

    </svg>

    <br>

    <!-- 堆叠的椭圆 -->

    <svg width="500" height="150">

        <ellipse cx="240" cy="100" rx="220" ry="30" fill="pink" />

        <ellipse cx="220" cy="70" rx="190" ry="20" fill="yellow" />

        <ellipse cx="210" cy="45" rx="170" ry="15" fill="puple" />

    </svg>

    <br>

    <!-- 视觉上的空心椭圆 -->

    <svg width="500" height="100">

        <ellipse cx="240" cy="50" rx="220" ry="30" fill="pink" />

        <ellipse cx="220" cy="50" rx="190" ry="20" fill="white" />

    </svg>

    <br>

4.绘制线

案例:

源代码:

 <svg width="500" height="210">

        <line x1="0" y1="0" x2="200" y2="200" stroke="red" stroke-width="2"> </line>

    </svg>

5.绘制多边形

案例:

源代码:

 <svg width="500" height="210">

        <polygon points="220,10 250,190 160,210" fill="lime" stroke="puple" stroke-width="1"/>

    </svg>

    <br>

    <svg width="500" height="250">

        <polygon points="220,10 300,210 170,250 123,234" fill="lime" stroke="puple" stroke-width="1"/>

    </svg>

    <br>

    <svg width="500" height="210">

        <polygon points="100,10 40,198 198,78 10,78 160,198" fill="lime" stroke="puple" stroke-width="1"/>

    </svg>

    <br>

6.绘制多线条

案例:

源代码:

<svg width="500" height="200">

        <polyline points="20,20 40,25 60,40 80,120 120,140 200,180" fill="none" stroke="black" stroke-width="3"/>

    </svg>

    <br>

    <svg width="500" height="180">

        <polyline points="0,40 40,40 40,80 80,80 80,120 120,120 120,160" fill="none" stroke="red" stroke-width="4"/>

    </svg>

    <br>

  • 18
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值