zoukankan      html  css  js  c++  java
  • 一步一步教你用CSS画爱心

    今天小颖给大家分享一个用CSS画的爱心,底下有代码和制作过程,希望对大家有所帮助。

    第一步:

           先画一个正方形。如图:

              

    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="utf-8">
        <title>css画桃心</title>
        <style media="screen">
            .heart-body {
                width: 500px;
                margin: 100px auto;
                position: relative;
            }
    
            .heart-shape {
                position: relative;
                width: 100px;
                height: 100px;
                background-color: #f70e0e;
            }
        </style>
    </head>
    
    <body>
        <div class="heart-body">
            <div class="heart-shape"></div>
        </div>
    </body>
    
    </html>

    第二步:

             将利用伪元素before和 :after,在正方形的左边和上边各画一个正方形,然后再利用border-radius: 50%;属性,修饰下这两个正方形,然后就得到了两个圆,如图所示:

                     

            .heart-shape:before,
            .heart-shape:after {
                position: absolute;
                content: '';
                width: 100px;
                height: 100px;
                background-color: #ffc0cb;
            }
    
            .heart-shape:before {
                left: -45px;
            }
    
            .heart-shape:after {
                top: -45px;
            }

     利用border-radius: 50%; 属性:

            .heart-shape:before,
            .heart-shape:after {
                position: absolute;
                content: '';
                width: 100px;
                height: 100px;
                -webkit-border-radius: 50%;
                /**兼容苹果;谷歌,等一些浏览器认*/
                -moz-border-radius: 50%;
                /**兼容火狐浏览器*/
                -o-border-radius: 50%;
                /**兼容opera浏览器*/
                border-radius: 50%;
                background-color: #ffc0cb;
            }

    第三步:

            类名为:heart-shape的div 利用transform: rotate(45deg); 属性将他们旋转45度,如图所示:

             

            .heart-shape {
                position: relative;
                width: 100px;
                height: 100px;
                background-color: #f70e0e;
                -webkit-transform: rotate(45deg);
                /* Safari 和 Chrome */
                -moz-transform: rotate(45deg);
                /* Firefox */
                -ms-transform: rotate(45deg);
                /* IE 9 */
                -o-transform: rotate(45deg);
                /* Opera */
                transform: rotate(45deg);
            }

    小颖把圆的背景色和正方形的背景色没给统一的颜色,是为了大家更好的看到明显的效果图,接下来小颖将其背景色设置成统一的,最终的爱心就出来了,如图所示:

        

            .heart-shape:before,
            .heart-shape:after {
                position: absolute;
                content: '';
                width: 100px;
                height: 100px;
                -webkit-border-radius: 50%;
                /**兼容苹果;谷歌,等一些浏览器认*/
                -moz-border-radius: 50%;
                /**兼容火狐浏览器*/
                -o-border-radius: 50%;
                /**兼容opera浏览器*/
                border-radius: 50%;
                background-color: #f70e0e;
            }
  • 相关阅读:
    bzoj 4897 天赋 有向图的矩阵数定理
    bzoj 4621 Tc605 思想+dp
    bzoj 4596 [Shoi2016]黑暗前的幻想乡 矩阵树定理+容斥
    bzoj 4455 [Zjoi2016]小星星 树形dp&容斥
    获取Android设备无线和以太网MAC地址
    Java WebSocket库:https://github.com/TooTallNate/Java-WebSocket
    UsbManager, UsbDevice的简单示例
    Android开发之开机自动启动应用
    使用Microsoft Office 2007将文档转换为PDF
    C/C++实现删除字符串的首尾空格
  • 原文地址:https://www.cnblogs.com/yingzi1028/p/6248937.html
Copyright © 2011-2022 走看看