css中 :after 选择器向选定的元素之后插入内容,使用content 属性来指定要插入的内容
p:after
{
content:"- Remember this";
}
利用after实现清除css中浮动
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .left{ float: left; } .container{ background-color: red; } .container .item{ width: 180px; height: 150px; background-color: #303a40; border: 1px solid red; } /*利用after 在对应div标签后添加内容,并设置内容不显示,从而达到当class=item这些标签浮动时,外面的div标签设置的背景色可以显示*/ .clearfix:after{ content: '.'; display: block; clear: both; visibility: hidden; height: 0; } </style> </head> <body> <div class="container clearfix"> <div class="item left"></div> <div class="item left"></div> <div class="item left"></div> <div class="item left"></div> <div class="item left"></div> <div class="item left"></div> <div class="item left"></div> <div class="item left"></div> </div> <div>asdf</div> <!--<div class="body clearfix">--> <!--<div class="item left"></div>--> <!--<div class="item left"></div>--> <!--<div class="item left"></div>--> <!--<div class="item left"></div>--> <!--</div>--> <!--<div class="test">ABC </div>--> </body> </html>
:hover在鼠标移到链接上时添加的特殊样式。:hover 选择器器可用于所有元素,不仅是链接。
a:hover
{
background-color:yellow;
}
// 当鼠标放在c1上时,c1下的c2才生效
.c1:hover .c2{
background-color:yellow;}
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .left{ float: left; } .clearfix:after{ content: '.'; display: block; clear: both; visibility: hidden; height: 0; } .container{ background-color: red; } .container .item{ width: 180px; height: 150px; background-color: #303a40; border: 1px solid red; overflow: hidden; position: relative; } .hide{ display: none; } .container .item:hover{ border: 1px solid green; } .container .item .text{ display: none; } /*鼠标放在class=item元素上后面class=text元素的样式 本例显示1000和背景色*/ .container .item:hover .text{ display: block; } </style> </head> <body> <div class="container clearfix"> <div class="item left"> <div class="bg"> <img style="height: 150px; width: 180px;" src="1.jpg"> </div> <div class="text"> <!--z-index 属性设置元素的堆叠顺序。拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面。--> <div style="z-index:9;position: absolute;left: 0;right: 0;top: 0;bottom: 0;background-color: red;opacity: 0.6"></div> <div style="z-index:10;position: absolute;left: 0;right: 0;top: 0;bottom: 0;">1000</div> </div> </div> </div> </body> </html>
后台管理界面例子
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> body{ margin: 0; } .left{ float: left; } .right{ float: right; } .hide{ display: none; } /***********设置class="pg-header"相关标签样式*************/ .pg-header{ height: 48px; line-height: 48px; background-color: #303a40; color: white; } .pg-header .logo{ float: left; width: 200px; text-align: center; } .pg-header .user{ padding: 0 20px; height: 48px; position: relative; } .pg-header .user:hover{ /*鼠标放上去显示的背景色*/ background-color: #425a66; } .pg-header .user .a{ height: 48px; } .pg-header .user .a img{ width: 40px; height: 40px; margin-top: 4px; border-radius: 50%; /*给元素的圆角边框*/ } .pg-header .user .more{ width:200px; border: 1px solid darkgreen; position: absolute; top:48px; right: 20px; background-color: #C0C0C0; display: none;/*设置元素不显示*/ z-index: 9999; } .pg-header .user .more a{ display: block; text-decoration: none; /*去掉a标签超链接中的下划线*/ } /*鼠标放在图片上时显示'我的信息、注销信息*/ .pg-header .user:hover .more{ display: block; } /***********设置class="pg-body"相关标签样式*************/ .pg-body .body-menu{ position: absolute; top: 50px; bottom: 0; left: 0; width: 200px; border: 1px solid #336699; } .pg-body .body-menu h1{ color: #fff; background-color: #425a66; font-size: 14px; } .pg-body .body-content{ position: absolute; top: 50px; bottom: 0; left: 210px; right: 0; border: 1px solid #336699; overflow: auto; z-index: 10; } .pg-body .body-content p{ display: block; height: 40px; } .back{ position: fixed; bottom: 0px; right: 0px; background-color: blue; } </style> </head> <body> <div class="pg-header"> <div class="logo">主机系统管理</div> <div class="user right" style="position: relative"> <a class="a"> <img src="dva01.jpg"> </a> <div class="more"> <a href="#">我的信息</a> <a href="#">注销</a> </div> </div> </div> <div class="pg-body"> <div class="body-menu"> <h1>机房管理</h1> <h1>主机管理</h1> </div> <div class="body-content"> <p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p> <p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p> <p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p> <p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p> <p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p> <p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p><p>aaaaaa</p> <div onclick="GoTop()" class="back">返回顶部</div> </div> </div> <div onclick="GoTop()" class="back hide">返回顶部</div> </body> <script src="jquery-3.1.1.js"></script> <script type="text/javascript"> function GoTop(){ //返回顶部 $('.body-content').scrollTop(0); } $(function(){ $('.body-content').scroll(function(){ //当滚动滑轮时,执行函数体 //获取当前滑轮滚动的高度 var top = $('.body-content').scrollTop(); if(top>40){ //展示“返回顶部” $('.back').removeClass('hide'); }else{ //隐藏“返回顶部” $('.back').addClass('hide'); } }); }); </script> </html>
Jquery动画效果
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <p style="display: none">hello world</p> <input id="show" type="button" value="显示"> <input id="hide" type="button" value="隐藏"> <input id="toggle" type="button" value="toggle"> <script src="jquery-2.1.4.min.js"></script> <script> $("#show").click(function () { $("p").show(2000,function () { alert(123) }); }); $("#hide").click(function () { $("p").hide(1000); }); $("#toggle").click(function () { $("p").toggle(1000); }); /*toggle元素若显示就隐藏,元素隐藏就显示 </script> </body> </html>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="div" style="display:none ;width: 200px;height: 200px;background-color: rebeccapurple"></div> <input id="In" type="button" value="fadeIn"> <input id="out" type="button" value="fadeout"> <input id="toggle" type="button" value="fadetoggle"> <input id="fadeto" type="button" value="fadeto"> <script src="jquery-3.1.1.js"></script> <script> $("#In").click(function () { $("div").fadeIn(2000); }) $("#out").click(function () { $("div").fadeOut(1000); }) $("#toggle").click(function () { $("div").fadeToggle(1000); }); /*fadeToggle元素是隐藏就显示,元素显示就隐藏*/ $("#fadeto").click(function () { $("div").fadeTo(1000,0.9); }); </script> </body> </html>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div style="border: 1px solid #ddd;width: 600px;position: absolute;"> <div id="title" style="background-color: black;height: 40px;color: white;"> 标题 </div> <div style="height: 300px;"> 内容 </div> </div> </body> <script type="text/javascript" src="jquery-3.1.1.js"></script> <script> $("#title").mouseover(function () { $(this).css("cursor","move") }).mousedown(function (event) { var start_x=event.screenX; var start_y=event.screenY; var parent_left=$(this).parent().offset().left; var parent_top=$(this).parent().offset().top; $(this).on("mousemove",function (e) { var new_x=e.screenX; var new_y=e.screenY; var new_parent_x=parent_left+(new_x-start_x); var new_parent_y=parent_top+(new_y-start_y); $(this).parent().css("left",new_parent_x+"px"); $(this).parent().css("top",new_parent_y+"px"); }).mouseup(function () { $(this).off("mousemove") }) }) </script> </html>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="jquery-2.1.4.min.js"></script> <script> $(document).ready(function(){ $("#flipshow").click(function(){ $("#content").slideDown(1000); }); $("#fliphide").click(function(){ $("#content").slideUp(1000); }); $("#toggle").click(function(){ $("#content").slideToggle(1000); }) }); </script> <style> #flipshow,#content,#fliphide,#toggle{ padding: 5px; text-align: center; background-color: blueviolet; border:solid 1px red; } #content{ padding: 50px; display: none; } </style> </head> <body> <div id="flipshow">出现</div> <div id="fliphide">隐藏</div> <div id="toggle">toggle</div> <div id="content">helloworld</div> </body> </html>