代码拉取完成,页面将自动刷新
<!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>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。