transform-origin:50% 0

transform-origin:50% 0

然后加上scale(-1,1)就相当于沿着中间那条线对称了一下不是吗,为什么还要改变translate的值才能完全对称呢?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        :root{--hl:#1b2f90;
              --bg:#f9f9f6  }

        .dog{width: 300px;height: 400px;
        position:relative;}

        .center{position: absolute;
        left: 50%;
        transform: translate(-50%,0);}

        .forehead{width: 102px;height: 48px;
        background: var(--bg);
        border-radius: 51px/40x 40px 8px 8px;}

        .face{width: 110px;
        height: 68px;
        background: var(--bg);
        border-radius: 51px / 40px 40px 8px 8px;top: 20px;z-index: 1;}

        .chin{width: 104px;
        height: 36px;
        background: var(--bg);
        border-radius: 52px / 0px 0px 36px 36px;
        top: 60px;z-index: 1;}
         
         .ear{width: 16px;
         height: 70px;
         background: var(--hl);
         border-radius: 50%;
         position: absolute;
         z-index: 0;
         left: 50%;
         top: 34px;
         transform: translate(-42px,0) rotate(10deg); }
         .ear.right{transform: scale(-1,1) translate(-26px,0) rotate(10deg) scale(-1,1);
         }
         .eye{width: 24px;
         height: 24px;
         background: var(--bg);
         border-radius: 12px/13px 12px 12px 2px;
         position: absolute;
         z-index: 2;
         left: 50%;
         top: 20px;
         transform-origin: 50% 0;
         transform:translate(-42px,0) rotate(10deg);
         box-shadow: 1px 0px 0px 0px #000 inset,-1px 0px 5px 1px #ddd;}
         .eye.right{transform: scale(-1,1) translate(-26px,0) rotate(10deg);}

    </style>
            
</head>
<body>
    <div class="dog">
        <div class="forehead center"></div>
        <div class="face center"></div>
        <div class="chin center"></div>
        <div class="ear"></div>
        <div class="ear right"></div>
        <div class="eye"></div>
        <div class="eye right"></div>
    </div>
    
</body>
</html>


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕星星 2019-10-17 10:49:42

同学你好,

翻转是参照耳朵自身的中心点进行的,不是参照脸中间的线哦。

http://img1.sycdn.imooc.com//climg/5da7d6c00953310012270588.jpg

并且transform相同属性是会覆盖之前设置的平移和旋转样式的,所以还需要设置平移和旋转才能完全对称。

自己可以再理解下,祝学习愉快!

欢迎采纳~

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师