css怎么实现心形
导读:收集整理的这篇文章主要介绍了css怎么实现心形,觉得挺不错的,现在分享给大家,也给大家做个参考。css实现心形的方法:首先利用“border-radius:100%”样式画两个正圆;然后进行定位,将两个圆重合一部分;接着画一个正方形,进行定...
收集整理的这篇文章主要介绍了css怎么实现心形,觉得挺不错的,现在分享给大家,也给大家做个参考。css实现心形的方法:首先利用“border-radius:100%”样式画两个正圆;然后进行定位,将两个圆重合一部分;接着画一个正方形,进行定位,将正方形与两个圆重合一部分,形成一个倾斜的心形;最后使用transform样式调整爱心角度。
本教程操作环境:windows7系统、CSS3& & HTML5版、Dell G3电脑。
前期预备知识:
明白正方形的画法。
明白圆形的画法。
明白什么是定位。
明白怎么旋转。
话不多说,先教大家怎么用css画一个圆形。
.disc1{ width: 100px; height: 100px; border:1px solid red; background-color: red; margin:300px 0px 0px 300px; border-radius:100%; float:left; }
由于我们的爱心是由两个圆和一个正方形组成的,所以我们还需要再来一个圆形。
.disc2{ width: 100px; height: 100px; border:1px solid red; background-color: red; margin:250px 0px 0px 0px; border-radius:100%; float:left; posITion: relative; right: 50px; }
第三步我们就需要做一个正方形了。
.square{ width: 100px; height: 100px; border:1px solid red; background-color: red; margin: 300px 0px 0px 0px; float: left; position: relative; right: 152px; }
做完这些的效果已经基本上出来了,但是我们还需要调整一下爱心的角度,这时就需要用到我们css样式中的transform中的rotate属性了。
我们由于需要把三个div都旋转角度,所以我们把这三个div放在一个div里面。具体代码如下:
.main{ transform: rotate(45deg); margin: 300px; }
做到现在,我们的爱心就已经做出来咯。效果图如下:
全部代码如下(包含HTML代码和CSS代码)
!DOCTYPE html> html> head> meta charset="utf-8" /> style> *{ margin: 0px; padding: 0px; } .main{ transform: rotate(45deg); margin: 300px; } .disc1{ width: 100px; height: 100px; border:1px solid red; background-color: red; margin:300px 0px 0px 300px; border-radius:100%; float:left; } .disc2{ width: 100px; height: 100px; border:1px solid red; background-color: red; margin:250px 0px 0px 0px; border-radius:100%; float:left; position: relative; right: 50px; } .square{ width: 100px; height: 100px; border:1px solid red; background-color: red; margin: 300px 0px 0px 0px; float: left; position: relative; right: 152px; } /style> /head> body> div class="main"> div class="disc1"> /div> div class="disc2"> /div> div class="square"> /div> /div> /body> /html>
(学习视频分享:css视频教程)
以上就是css怎么实现心形的详细内容,更多请关注其它相关文章!
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: css怎么实现心形
本文地址: https://pptw.com/jishu/589500.html