1 Star 0 Fork 0

math.most/html-css

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
009伪元素选择器(before after).html 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
math.most 提交于 2021-09-27 19:40 +08:00 . first commit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>伪元素选择器</title>
<style>
body {
padding: 200px;
}
div:nth-of-type(1) {
width: 300px;
height: 200px;
background-color: red;
float: left;
}
div:nth-of-type(2) {
width: 100px;
height: 200px;
background-color: blue;
float: left;
position: relative;
}
div:nth-of-type(2)::before {
content: "";
width: 20px;
height: 20px;
background-color: #fff;
border-radius: 10px;
position: absolute;
top: -10px;
left: -10px;
}
div:nth-of-type(2)::after {
content: "";
width: 20px;
height: 20px;
background-color: #fff;
border-radius: 10px;
position: absolute;
left: -10px;
bottom: -10px;
}
</style>
</head>
<body>
<!-- 完全等价于一个dom元素, 但是不会在dom树中生成 -->
<!-- 1. before: 定义一个元素内容·前·插入content属性定义的内容与样式 -->
<!-- 2. after: 定义一个元素内容·后·插入content属性定义的内容与样式 -->
<!-- 使用before after要求 -->
<!-- 1. 必须添加content属性,否则后期不可见 -->
<!-- 2. 默认为行内元素;如果想设置宽高,需要转换为块级元素 -->
<!-- 3. 后期无法通过js操作 -->
<div></div>
<div></div>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mathmost/html-css.git
git@gitee.com:mathmost/html-css.git
mathmost
html-css
html-css
master

搜索帮助