One of the most popular shapes in the world is the heart shape, and in this challenge you'll create one using pure CSS.

But first, you need to understand the ::before and ::after pseudo-elements.

These pseudo-elements are used to add something before or after a selected element.

In the following example, a ::before pseudo-element is used to add a rectangle to an element with the class heart:

.heart::before {
content: "";
background-color: yellow;
border-radius: %;
position: absolute;
height: 50px;
width: 70px;
top: -50px;
left: 5px;
}

For the ::before and ::after pseudo-elements to function properly, they must have a defined content property.

This property is usually used to add things like a photo or text to the selected element. When the ::before and ::after pseudo-elements are used to make shapes, the content property is still required, but it's set to an empty string.

In the above example, the element with the class of heart has a ::before pseudo-element that produces a yellow rectangle with height and width of 50px and 70px, respectively.

This rectangle has round corners due to its 25% border radius and is positioned absolutely at 5px from the left and 50px above the top of the element.

练习题:

Transform the element on the screen to a heart. In the heart::after selector, change the background-color to pink and the border-radius to 50%.

Next, target the element with the class heart (just heart) and fill in the transform property. Use the rotate() function with -45 degrees.

Finally, in the heart::before selector, set its content property to an empty string.

练习代码:

 <style>
.heart {
position: absolute;
margin: auto;
top: ;
right: ;
bottom: ;
left: ;
background-color: pink;
height: 50px;
width: 50px;
transform: rotate(-45deg);
}
.heart::after {
background-color: pink;
content: "";
border-radius: %;
position: absolute;
width: 50px;
height: 50px;
top: 0px;
left: 25px;
}
.heart::before {
content: "";
background-color: pink;
border-radius: %;
position: absolute;
width: 50px;
height: 50px;
top: -25px;
left: 0px;
}
</style>
<div class="heart"></div>

效果:

刚刚自己又抄写了一遍。

  • 先做个粉色的方形
  • 再做2个伪元素,调好边界半径,依次叠加出2个心型的圆屁股

FCC---Create a More Complex Shape Using CSS and HTML---一个粉色爱心的更多相关文章

  1. 怎样将多个CSS文件导入一个CSS文件中

    问题: 在HTML中引入css的其中的两个方法:    导入式和链接式的目的都是将一个独立的css文件引入一个文件中,二者的区别不大,事实上,二者最大的区别在于链接式使用html的标记引入外部css文 ...

  2. 何使用CSS写出一个下拉菜单。

    导航菜单是每个网站所必备的功能,也是每个学习制作网站的朋友所必须接触的,如何用css样式制作一个简单漂亮的二级下拉菜单呢? 下面为大家分享一下我的经验 方法步骤: 第一步  : 首页我们打开Subli ...

  3. 用HTML+CSS画出一个同心圆

    参加web前端校招的同学们经常会遇到这样的面试题:用HTML+CSS画出一个同心圆. 例如: 这道题主要考验的是基础盒模型布局能力和倒圆角属性的巧用. 1.html代码 <body> &l ...

  4. div+css 怎么让一个小div在另一个大div里面 垂直居中

    div+css 怎么让一个小div在另一个大div里面 垂直居中 方法1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 .parent {           width:800 ...

  5. Css中实现一个盒子固定宽度,另一个盒子宽度自适应的方法

    Css中实现一个盒子固定宽度,另一个盒子宽度自适应的方法 网上方法很多,个人认为以下两种思想是最为常用的. 一种是让第一个盒子脱离文档流,第二个盒子离左边有一定距离. 第二种方法是使用flex布局,不 ...

  6. 用css做出来一个三角形

    用css做出来一个三角形      <!--不设置宽高  转换行内块  边线设置成宽度-->       <div class="triangle"> 三角 ...

  7. No.6 - 利用 CSS animation 制作一个炫酷的 Slider

    *{ margin:; padding:; } div{ margin: auto; width: 800px; height: 681px; position: relative; overflow ...

  8. 百度前端技术学院2018笔记 之 利用 CSS animation 制作一个炫酷的 Slider

    前言 题目地址 利用 CSS animation 制作一个炫酷的 Slider 思路整理 首先页面包含三种东西 一个是type为radio的input其实就是单选框 二是每个单选框对应的label 三 ...

  9. HTML & CSS & JavaScript 从一个表格到一个灰阶颜色表(目录)

    HTML & CSS & JavaScript 从一个表格到一个灰阶颜色表 01 HTML & CSS & JavaScript 从一个表格到一个灰阶颜色表 02 HT ...

随机推荐

  1. MFC图形编辑界面工具

    一.背景 喔,五天的实训终于结束了,学校安排的这次实训课名称叫高级程序设计实训,但在我看来,主要是学习了Visual C++ .NET所提供的MFC(Microsoft Foundation Clas ...

  2. zabbix监控服务

    1.模板的重要 ​ 1.手动添加监控比较麻烦,监控项 -> 图形 -> 触发器. 问题: 1.例如: 100台服务器需要检查81端口 2.例如: 100台服务器81改成82 解决: 使用模 ...

  3. Scrapy_redis主机连接虚拟机的数据库时显示积极拒绝,无法连接

    1.端口转发 在虚拟机设置各个数据库对应的端口转发 2.修改数据库配置文件 默认只有本机的IP才可以访问,其它IP就连不上了,修改bind ip  为0.0.0.0 3.重启服务(或者直接重启虚拟机) ...

  4. docker 限制容器能够使用的资源

    docker 限制容器能够使用的内存,CPU,I/O 资源概述,内存是非可压缩资源,cpu是可压缩资源. 内存用超了,就发送Out Of Memory Exception,容器会被kill掉.所以内存 ...

  5. limit的优化

    SELECT * FROM t_fly WHERE fly_id IN (8888,1,24,6666); 查询速度很快,对于一些过万数据的查询,mysql也能轻松的查询出来

  6. 80道最新java基础部分面试题(五)

    自己整理的面试题,希望可以帮到大家,需要更多资料的可以私信我哦,大家一起学习进步! 48.同步和异步有何异同,在什么情况下分别使用他们?举例说明.  如果数据将在线程间共享.例如正在写的数据以后可能被 ...

  7. jenkins报错:Problem accessing /jenkins/. Reason: HTTP ERROR 404

    这是一个Jenkins的Bug.临时解决方法是:在浏览器中手工输入:http://<ip>:<port>.不要访问"/jenkins"这个路径.

  8. WPF/C# 快捷键 自动生成方法

    原文:WPF/C# 快捷键 自动生成方法 这一篇文章会很短~ 在写依赖属性的会后   propdb 会自动生成依赖属性所有的内容 但是如果我写属性变化通知的时候   希望有一个快捷键能自动生成方法 怎 ...

  9. 关于sublime建立python工程的说明

    https://www.zhihu.com/question/22681628此链接说明的不错,可以参考. 为了方便使用sublime,难免要定义一些快捷键,https://www.whidy.net ...

  10. 2019徐州网络赛 I J M

    I. query 比赛时候没有预处理因子疯狂t,其实预处理出来因子是\(O(nlog(n))\)级别的 每个数和他的因子是一对偏序关系,因此询问转化为(l,r)区间每个数的因子在区间(l,r)的个数 ...