博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用纯CSS画一颗爱心
阅读量:4117 次
发布时间:2019-05-25

本文共 1754 字,大约阅读时间需要 5 分钟。

来源 | https://www.cnblogs.com/liu-en-ci/p/6721963.html

CSS是一个需要深度挖掘的东西,里面有很多样式属性,掌握几个常用的便可以实现很好看的效果,例如用CSS画爱心。

前期预备知识:

  1. 明白正方形的画法。

  2. 明白圆形的画法。

  3. 明白什么是定位。

  4. 明白怎么旋转。

话不多说,先教大家怎么用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属性了。

我们由于需要把三个p都旋转角度,所以我们把这三个p放在一个p里面。具体代码如下:

.main{    transform: rotate(45deg);    margin: 300px;}

做到现在,我们的爱心就已经做出来咯。效果图如下:

全部代码如下(包含HTML代码和CSS代码)

            
*{    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;}

本文完〜

你可能感兴趣的文章
Bitcode
查看>>
If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
查看>>
Undefined symbols for architecture armv7: "_OBJC_CLASS_$_CTTelephonyNetworkInfo", referenced from:
查看>>
"This app is not allowed to query for scheme ***"
查看>>
去掉UITableView的Cell选中状态
查看>>
target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.
查看>>
iOS 将内容复制到剪切板
查看>>
UITableView自定义cell更换选中的背景色
查看>>
iOS 使屏幕常亮代码
查看>>
Xcode移除项目中的CocoaPods
查看>>
-canOpenURL: failed for URL: "wechat://" - error: "This app is not allowed to query for scheme wech
查看>>
MPMediaItemPropertyAssetURL 属性获取的URL为空
查看>>
改变UITableViewCellAccessoryCheckmark(UITableView Cell后面的对勾)的颜色
查看>>
UITableView滚动时动态改变Header的背景色
查看>>
OpenAL基本介绍
查看>>
关于iPhone手机如何导入本地音乐
查看>>
关于iOS从iPod取出来的音乐MPMediaItemPropertyAssetURL属性为空问题
查看>>
iOS [UIScreen mainScreen].scale
查看>>
iOS 检查手机的3D Touch是否可用
查看>>
获取AppDelegate对象
查看>>