CSS3变形-扭转实现4色花-案例解析(代码实例)
本文目标:
1、把握CSS3中怎样让元素扭转
问题:
1、实现以下结果,且使用纯DIV+CSS
附加说明:
1、带蝴蝶的粉色圆圈是一张图片
2、中心的“4色花”是由4个半圆通过扭转生成的,每个半圆的直径为180px
此刻来详细操纵
1、预备素材:当前案例的素材为带蝴蝶的粉色圆圈
2、创立好index.html,写好架构,架构怎样剖析呢
思绪剖析:
1、目标外层是一个div,div的背景图片为一个带蝴蝶的粉色圆圈
2、div内包括一朵4色花,所以这朵花由5个部分组成,4个花瓣+1个白色小孔心
好,先依照剖析,写好思绪,临时不管css的实现
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CSS扭转案例</title> </head> <body> <div class="wrapper"> <div class="bottole"> <div class="leaf leaf2"></div> <div class="leaf leaf3"></div> <div class="leaf leaf4"></div> <div class="leaf"></div> <div class="smallcircle"></div> </div> </div> </body> </html>
3、写样式 ,创立css文件夹,里面创建index.css
思绪剖析:
.container * 公共样式
1、定义公共样式
.wrapper *{ margin:0; padding:0; }
.bottole 外层div设定
1、由于要包管背景图片完全显示出来,所以必然要大于背景图片
2、背景图片不克不及反复
.bottole{ width: 640px; height: 420px; background-image: url(../images/pao.png); background-repeat: no-repeat; background-position-x: 40px; background-position-y: -35px; }
.leaf 半圆 叶子
1、由于半圆直径为180,所以高度必定是90px,然后半圆我们可以通过border-radius实现,且默许色彩我们就定义为橙色,为了让4个半圆重叠在一起,就必需使用position:absolute,然后需要设定margin-left,margin-top让它的位置显现目标结果(这里我们可以通过不竭调试得出)
.wrapper .leaf { width: 180px; height: 90px; border-radius: 180px 180px 0 0; background-color: orange; position: absolute; margin-left: 100px; margin-top: 150px; }
.leaf2 叶子独自设定
1、该叶子的色彩为绿色,且需要扭转90度
.wrapper .leaf2 { background: green; -webkit-transform: rotate(90deg); transform: rotate(90deg); }
.leaf3 叶子独自设定
1、该叶子的色彩为蓝色,且需要扭转180度
.wrapper .leaf3 { background: blue; -webkit-transform: rotate(180deg); transform: rotate(180deg); }
.leaf4 叶子独自设定
1、该叶子的色彩为红色,需要扭转的角度为270度
.wrapper .leaf4 { background: red; -webkit-transform: rotate(270deg); transform: rotate(270deg); }
小圆孔 花心设定
1、小圆孔大小为20,我们可以让一个div大小都为20,然后border-radius也为20就可以制作成一个圆
2、背风光为白色
3、为了让孔位于花朵中心,我们需要设定margin-left,margin-top
.smallcircle{ width: 20px; height: 20px; background-color: white; border-radius: 20px; position: absolute; margin-left: 180px; margin-top: 190px; }
好,到当前为止,我们把想到的样式全部写好了,详细不合错误,我们再来修改
当前为止,css所有内容如下:
.wrapper *{ margin:0; padding:0; } .bottole{ width: 640px; height: 420px; border-radius: 400px; background-image: url(../images/pao.png); background-repeat: no-repeat; background-position-x: 40px; background-position-y: -35px; } .wrapper .leaf { width: 180px; height: 90px; border-radius: 180px 180px 0 0; background-color: orange; position: absolute; margin-left: 100px; margin-top: 150px; } .wrapper .leaf2 { background: green; -webkit-transform: rotate(90deg); transform: rotate(90deg); } .wrapper .leaf3 { background: blue; -webkit-transform: rotate(180deg); transform: rotate(180deg); } .wrapper .leaf4 { background: red; -webkit-transform: rotate(270deg); transform: rotate(270deg); } .smallcircle{ width: 20px; height: 20px; background-color: white; border-radius: 20px; position: absolute; margin-left: 180px; margin-top: 190px; }
将css引入index.html中
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CSS扭转案例</title> <link href="css/index.css" rel="stylesheet" type="text/css"> </head> <body> <div class="wrapper"> <div class="bottole"> <div class="leaf leaf2"></div> <div class="leaf leaf3"></div> <div class="leaf leaf4"></div> <div class="leaf"></div> <div class="smallcircle"></div> </div> </div> </body> </html>
运转结果如下:
总结:
1、学习了在css中怎样让元素扭转
以上就是CSS3变形-扭转实现4色花-案例解析(代码实例)的具体内容,更多请关注百分百源码网其它相关文章!