:before和:after伪元素的常见用法总结_html/css_WEB-ITnose
1. 利用content属性,为元素添加内容修饰:
1) 添加字符串:
使用引号包括一段字符串,将会向元素内容中添加字符串。栗子:
a:after { content: "after content"; }
2) 使用attr()方法,调用当前元素的属性的值:
栗子:
a:after { content: attr(href); }a:after { content: attr(data-attr); }
3)使用url()方法,引用多媒体文件:
栗子:
a::before { content: url(logo.png); }
4) 使用counter()方法,调用计时器:
栗子:
h:before { counter-increment: chapter; cotent: "Chapter " counter(chapter) ". " }
2. 清除浮动:
.clear-fix { *overflow: hidden; *zoom: 1; }.clear-fix:after { display: table; content: ""; width: 0; clear: both; }
3. 特效妙用:
// CSS代码a { position: relative; display: inline-block; text-decoration: none; color: #000; font-size: 32px; padding: 5px 10px;}a::before, a::after { content: ""; transition: all 0.2s;}a::before { left: 0;}a::after { right: 0;}a:hover::before, a:hover::after { position: absolute;}a:hover::before { content: "\5B"; left: -20px; }a:hover::after { content: "\5D"; right: -20px; }// HTML代码<a href="#">我是个超链接</a>
4. 特殊形状的实现:
举个栗子:(譬如对话气泡)
// CSS代码.tooltip { position: relative; display: inline-block; padding: 5px 10px; background: #80D4C8;}.tooltip:before { content: ""; display: block; position: absolute; left: 50%; margin-left: -5px; bottom: -5px; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 5px solid #80D4C8;}// HTML代码<div class="tooltip">I'm a tooltip.</div>

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题











HTML适合初学者学习,因为它简单易学且能快速看到成果。1)HTML的学习曲线平缓,易于上手。2)只需掌握基本标签即可开始创建网页。3)灵活性高,可与CSS和JavaScript结合使用。4)丰富的学习资源和现代工具支持学习过程。

HTML定义网页结构,CSS负责样式和布局,JavaScript赋予动态交互。三者在网页开发中各司其职,共同构建丰富多彩的网站。

AnexampleOfAstartingTaginHtmlis,beginSaparagraph.startingTagSareEssentialInhtmlastheyInitiateEllements,defiteTheeTheErtypes,andarecrucialforsstructuringwebpages wepages webpages andConstructingthedom。

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

GiteePages静态网站部署失败:404错误排查与解决在使用Gitee...

网页批注功能的Y轴位置自适应算法本文将探讨如何实现类似Word文档的批注功能,特别是如何处理批注之间的间�...

实现图片点击后周围图片散开并放大效果许多网页设计中,需要实现一种交互效果:点击某张图片,使其周围的...

HTML、CSS和JavaScript是Web开发的三大支柱。1.HTML定义网页结构,使用标签如、等。2.CSS控制网页样式,使用选择器和属性如color、font-size等。3.JavaScript实现动态效果和交互,通过事件监听和DOM操作。
