1、第一个步骤http://jquery.lukelutman.com/plugins/pseudo/ 下载 jq-pseudo.js
下载好了,就引入jQuery和jq-pseudo.js
2、书写选择器的语法:
选择器:before, 选择器 {
/*兼容IE6、IE7*/
before: ‘要写的内容‘;
/*兼容IE8*/
content: ‘要写的内容‘;
}
对伪元素进行设置样式:
选择器:before, 选择器 .before {
书写样式
}
demo:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html> 3 <head> 4 <title>Basic Example - jQuery Pseudo Plugin</title> 5 <script type="text/javascript" src="jquery.js"></script> 6 <script type="text/javascript" src="jquery.pseudo.js"></script> 7 <script type="text/javascript"> 8 $(function(){ 9 $(‘#on‘).bind(‘click‘, function(e){ 10 $(‘body‘).addClass(‘toggle‘); 11 e.preventDefault(); 12 }); 13 $(‘#off‘).bind(‘click‘, function(e){ 14 $(‘body‘).removeClass(‘toggle‘); 15 e.preventDefault(); 16 }); 17 }); 18 </script> 19 <style type="text/css"> 20 21 p:before, p { 22 before: ‘foo ‘; 23 content: ‘foo ‘; } 24 25 p:after, p { 26 after: ‘ bar‘; 27 content: ‘ bar‘; } 28 29 p:before, p .before { 30 color: blue; } 31 32 p:after, p .after { 33 color: red; } 34 35 </style> 36 </head> 37 <body> 38 <h1>Basic Example - jQuery Pseudo Plugin</h1> 39 <p>« <a href="index.html">Back to the jQuery Pseudo Plugin</a></p> 40 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> 41 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> 42 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> 43 </body> 44 </html>
时间: 2024-10-12 18:47:40