background-position 不生效的问题
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>CSS3实现图片滑动效果</title> <link rel="stylesheet" type="text/css" href="css/common.css"> </head> <body> <div class="container"> <header> <h1>Slibing Image Pannels <span>with CSS3</span></h1> <nav > <a href="index.html" class="current-demo">Demo1</a> <a href="index2.html">Demo2</a> <a href="index3.html">Demo3</a> <a href="index4.htmml">Demo4</a> </nav> </header> <section> <div class="main"> <input type="radio" id="select-img-01" name="selectimg" class="selectImg-01" checked> <label for="select-img-01">1</label> <input type="radio" id="select-img-02" name="selectimg" class="selectImg-02" > <label for="select-img-02">2</label> <input type="radio" id="select-img-03" name="selectimg" class="selectImg-03" > <label for="select-img-03">3</label> <input type="radio" id="select-img-04" name="selectimg" class="selectImg-04" > <label for="select-img-04">4</label> <!-- 背景区域 --> <div class="back"> <div> <span></span> <span></span> <span></span> <span></span> </div> <div> <span></span> <span></span> <span></span> <span></span> </div> <div > <span></span> <span></span> <span></span> <span></span> </div> <div> <span></span> <span></span> <span></span> <span></span> </div> </div> </div> </section> </div> </body> </html>
/* CSS reset */ /* 考虑性能优化问题,所以不使用通配符*/ html,body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { margin:0; padding:0; } ol,ul { list-style:none; } h1,h2,h3,h4,h5,h6 { font-size:100%; /*h标签默认粗体*/ font-weight:normal; } a{ text-decoration: none; } /*公共页面样式*/ body{ background: url(../images/bg.jpg); font-size:15px; font-family:"Microsoft YaHei",微软雅黑,"MicrosoftJhengHei",华文细黑,STHeiti,MingLiu; } .container{ width:100%; height:100%; overflow-y: scroll; /*当y轴溢出的时候出现滚动条*/ text-align: center; /*当子元素不存在时候,自动应用父级样式*/ position: relative; } .container > header{ padding:20px 20px 10px 20px; margin-bottom: 30px; text-shadow:1px 1px 1px rgba(0,0,0,0.2); /*给文字加上阴影效果*/ } .container > header > h1{ font-size:35px; line-height:35px; padding-bottom: 10px; color:rgba(26,89,120,0.8); } .container > header > h1 >span{ color:#7cbcd6; text-shadow: 0px 1px 1px rgba(255,255,255,0.8); } .container > header > nav{ padding: 14px; } .container > header > nav > a{ display: inline-block; width: 60px; height: 60px; line-height: 60px; text-align: center; font-size: 11px; background: rgba(104,171,194,0.5); border-radius: 50%; color: #fff; font-style: italic; font-weight: 800; margin: 0px 5px; text-shadow: 1px 1px 1px rgba(0,0,0,0.1); box-shadow: 1px 1px 1px rgba(0,0,0,0.1) inset; } .container > header > nav > .current-demo, .container > header > nav > .current-demo:hover{ color:rgba(104,171,194,0.5); background: rgba(255,255,255,0.9); box-shadow: 0px 1px 1px rgba(0,0,0,0.2); } .container > header > nav > a:hover{ color:#fff; background: #4fa2c4; } .main{ width:600px; height: 400px; border: 20px solid #fff; margin: 30px auto; position: relative; } .main > input { display: none; } .main > label{ display: block; width: 150px; height: 30px; float: left; margin-top: 350px; color:#fff; font-style: italic; font-weight: 400; font-size: 18px; position: relative; z-index: 1000; text-align: center; line-height: 30px; } .main > label:before{ width: 30px; height: 30px; display: block; background: rgba(104,171,194,0.5); border-radius: 50%; content: ""; position: absolute; left:50%; margin-left: -13px; z-index: -1; box-shadow:0 0 0px 4px rgba(255,255,255,0.5); } .main > input:checked + label{ color:#68abc2; } .main > input:checked + label:before{ background: #fff; box-shadow:0 0 0px 4px rgba(104,171,194,0.5); } .main > label:after{ content: ""; display: block; width: 1px; height: 400px; position: absolute; top: -350px; right: 0; background: -webkit-linear-gradient(rgba(255,255,255,0.1), rgba(255,255,255,0.8)); background: -moz-linear-gradient(rgba(255,255,255,0.1), rgba(255,255,255,0.8)); background: -o-linear-gradient(rgba(255,255,255,0.1), rgba(255,255,255,0.8)); background: linear-gradient(rgba(255,255,255,0.1), rgba(255,255,255,0.8)); } .main > label:last-child:after{ width:0; /*最后一个不需要白线*/ } .main > .back{ width: 100%; height: 100%; position: absolute; left:0; top:0; -webkit-transition:left 0.5s ease-in-out; -moz-transition:left 0.5s ease-in-out; -o-transition:left 0.5s ease-in-out; transition:left 0.5s ease-in-out; } .main > .back > div{ width: 150px; height:400px; overflow: hidden; position: relative; float: left; } .main > .back > div > span{ width:100%; height: 100%; display: block; float: left; position: absolute; top:0; left: -150px; /*往右平移时候用*/ background-repeat: no-repeat; } /*点input被选中后 同步背景选择*/ .main > input.selectImg-01:checked ~ .back, .main > .back > div > span:nth-child(1){ background: url(../images/1.jpg) no-repeat; } .main > input.selectImg-02:checked ~ .back, .main > .back > div > span:nth-child(2) { background: url(../images/2.jpg) no-repeat; } .main > input.selectImg-03:checked ~ .back, .main > .back > div > span:nth-child(3) { background: url(../images/3.jpg) no-repeat; } .main > input.selectImg-04:checked ~ .back, .main > .back > div > span:nth-child(4) { background: url(../images/4.jpg) no-repeat; } /*每个div下的span做平移*/ .back > div:first-of-type > span { background-position: 0px 0px ; } .back > div:nth-of-type(2) > span { background-position: -150px 0px ; } .back > div:nth-of-type(3) > span { background-position: -300px 0px ; } .back > div:nth-of-type(4) > span { background-position: -450px 0px ; } .main > input.selectImg-01:checked ~ .back > div > span:nth-child(1), .main > input.selectImg-01:checked ~ .back > div > span:nth-child(2), .main > input.selectImg-01:checked ~ .back > div > span:nth-child(3), .main > input.selectImg-01:checked ~ .back > div > span:nth-child(4){ left:0px; z-index: 10; }
13
收起
正在回答 回答被采纳积分+1
2回答
qq_ToutAn諾尘_0
2018-05-30 13:22:00
F12 background-position 被划掉了,不生效
HTML5与CSS3实现动态网页 2018
- 参与学习 1887 人
- 提交作业 4643 份
- 解答问题 5760 个
有HTML和CSS基础,却不知道如何进阶?本路径带你通过系统学习,完成从“会做网页”到“做出好的动态网页”的蜕变,迈出成为前端工程师的第一步。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星