为了账号安全,请及时绑定邮箱和手机立即绑定

为什么:before和:after伪元素需要'content'属性?

为什么:before和:after伪元素需要'content'属性?

胡说叔叔 2019-08-05 15:40:30
为什么:before和:after伪元素需要'content'属性?鉴于以下场景,为什么:after选择器需要内容属性才能运行?.test {     width: 20px;     height: 20px;     background: blue;     position:relative;} .test:after {     width: 20px;     height: 20px;     background: red;     display: block;     position: absolute;     top: 0px;     left: 20px;}<div class="test"></div>注意在指定content属性之前如何看不到伪元素:.test {     width: 20px;     height: 20px;     background: blue;     position:relative;} .test:after {     width: 20px;     height: 20px;     background: red;     display: block;     position: absolute;     top: 0px;     left: 20px;     content:"hi";}<div class="test"></div>为什么这是预期的功能?你会认为显示块会强制元素出现。奇怪的是,您实际上可以在Web调试器中看到样式; 但是,它们不会显示在页面上。
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 2677 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信