FCC---Create a More Complex Shape Using CSS and HTML---一个粉色爱心
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---一个粉色爱心的更多相关文章
- 怎样将多个CSS文件导入一个CSS文件中
问题: 在HTML中引入css的其中的两个方法: 导入式和链接式的目的都是将一个独立的css文件引入一个文件中,二者的区别不大,事实上,二者最大的区别在于链接式使用html的标记引入外部css文 ...
- 何使用CSS写出一个下拉菜单。
导航菜单是每个网站所必备的功能,也是每个学习制作网站的朋友所必须接触的,如何用css样式制作一个简单漂亮的二级下拉菜单呢? 下面为大家分享一下我的经验 方法步骤: 第一步 : 首页我们打开Subli ...
- 用HTML+CSS画出一个同心圆
参加web前端校招的同学们经常会遇到这样的面试题:用HTML+CSS画出一个同心圆. 例如: 这道题主要考验的是基础盒模型布局能力和倒圆角属性的巧用. 1.html代码 <body> &l ...
- 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 ...
- Css中实现一个盒子固定宽度,另一个盒子宽度自适应的方法
Css中实现一个盒子固定宽度,另一个盒子宽度自适应的方法 网上方法很多,个人认为以下两种思想是最为常用的. 一种是让第一个盒子脱离文档流,第二个盒子离左边有一定距离. 第二种方法是使用flex布局,不 ...
- 用css做出来一个三角形
用css做出来一个三角形 <!--不设置宽高 转换行内块 边线设置成宽度--> <div class="triangle"> 三角 ...
- No.6 - 利用 CSS animation 制作一个炫酷的 Slider
*{ margin:; padding:; } div{ margin: auto; width: 800px; height: 681px; position: relative; overflow ...
- 百度前端技术学院2018笔记 之 利用 CSS animation 制作一个炫酷的 Slider
前言 题目地址 利用 CSS animation 制作一个炫酷的 Slider 思路整理 首先页面包含三种东西 一个是type为radio的input其实就是单选框 二是每个单选框对应的label 三 ...
- HTML & CSS & JavaScript 从一个表格到一个灰阶颜色表(目录)
HTML & CSS & JavaScript 从一个表格到一个灰阶颜色表 01 HTML & CSS & JavaScript 从一个表格到一个灰阶颜色表 02 HT ...
随机推荐
- 获取windows操作系统所有用户
一.知识点简单介绍 1. 利用WindowsApi获取 [DllImport("Netapi32.dll ")] extern static int NetUserEnum([Ma ...
- 【TencentOS tiny】深度源码分析(5)——信号量
信号量 信号量(sem)在操作系统中是一种实现系统中任务与任务.任务与中断间同步或者临界资源互斥保护的机制.在多任务系统中,各任务之间常需要同步或互斥,信号量就可以为用户提供这方面的支持. 抽象来说, ...
- RabbitMQ与Spring的框架整合之Spring Boot实战
1.RabbitMQ与Spring的框架整合之Spring Boot实战. 首先创建maven项目的RabbitMQ的消息生产者rabbitmq-springboot-provider项目,配置pom ...
- 手机分辨率DPI怎么计算
长度方向像素数平方加宽度方向像素平方然后开根号,最后除以屏幕大小(英寸)
- ThinkPHP中框架查询
1.查询多条数据 1.1静态调用all方法或者select方法 // 获取所有数据 all 和 select $list = User::all(); // 根据主键获取多个数据al ...
- SAP会计年度变式
会计年度变式用来确定SAP系统中每个公司的会计记账期间的变式.顾名思议,每个公司的会计年度变式必须与其实际使用的会计年度匹配. 在SAP系统中,每个会计年度最多允许有16个记账期间,其中 ...
- ssh免密登录配置后,登陆失败问题
本文转自博主:_Lance 本文转自:https://blog.csdn.net/qq_19648191/article/details/54845440 相关资料http://blog.csdn.n ...
- Paper慢慢读 - AB实验人群定向 Recursive Partitioning for Heterogeneous Casual Effects
这篇是treatment effect估计相关的论文系列第一篇所以会啰嗦一点多给出点背景. 论文 Athey, S., and Imbens, G. 2016. Recursive partition ...
- 四、排序算法总结二(归并排序)(C++版本)
一.什么是归并排序? 归并排序是基于分而治之的思想建立起来的. 所谓的分而治之,也就是将一个数据规模为N的数据集,分解为两个规模大小差不多的数据集(n/2),然而分别处理这两个更小的问题,就相当于解决 ...
- Less(3)
1.先判断注入类型 (1)首先看到要求,要求传一个ID参数,并且要求是数字型的:?id=1 (2)再输入?id=1' 显示报错,报错信息多了一个括号,判断接收到的参数可能为id=('1') (3)输入 ...