background-position 不生效的问题

background-position 不生效的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* 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-decorationnone;
}
/*公共页面样式*/
body{  
    backgroundurl(../images/bg.jpg);
    font-size:15px;
    font-family:"Microsoft YaHei",微软雅黑,"MicrosoftJhengHei",华文细黑,STHeiti,MingLiu;
}
.container{
    width:100%;
    height:100%;
    overflow-y: scroll/*当y轴溢出的时候出现滚动条*/
    text-aligncenter/*当子元素不存在时候,自动应用父级样式*/
    positionrelative;
}
.container > header{
    padding:20px 20px 10px 20px;
    margin-bottom30px;
    text-shadow:1px 1px 1px rgba(0,0,0,0.2); /*给文字加上阴影效果*/
}
.container > header > h1{
    font-size:35px;
    line-height:35px;
    padding-bottom10px;
    color:rgba(26,89,120,0.8);
}
.container > header > h1 >span{
    color:#7cbcd6;
    text-shadow0px 1px 1px rgba(255,255,255,0.8);
}
.container > header > nav{
    padding14px;
}
.container > header > nav > a{
    display: inline-block;
    width60px;
    height60px;
    line-height60px;
    text-aligncenter;
    font-size11px;
    background: rgba(104,171,194,0.5);
    border-radius: 50%;
    color#fff;
    font-styleitalic;
    font-weight800;
    margin0px 5px;
    text-shadow1px 1px 1px rgba(0,0,0,0.1);
    box-shadow: 1px 1px 1px rgba(0,0,0,0.1inset;
}
.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;
    height400px;
    border20px solid #fff;
    margin30px auto;
    positionrelative;
}
.main > input {
    displaynone;
}
.main > label{
    displayblock;
    width150px;
    height30px;
    floatleft;
    margin-top350px;
    color:#fff;
    font-styleitalic;
    font-weight400;
    font-size18px;
    positionrelative;
    z-index1000;
    text-aligncenter;
    line-height30px;
}
.main > label:before{
    width30px;
    height30px;
    displayblock;
    background: rgba(104,171,194,0.5);
    border-radius: 50%;
    content"";
    positionabsolute;
    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"";
    displayblock;
    width1px;
    height400px;
    positionabsolute;
    top-350px;
    right0;
    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{
    width100%;
    height100%;
    positionabsolute;
    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{
    width150px;
    height:400px;
    overflowhidden;
    positionrelative;
    floatleft;
     
}
.main > .back > div > span{
    width:100%;
    height100%;
    displayblock;
    floatleft;
    positionabsolute;
    top:0;
    left-150px/*往右平移时候用*/
    background-repeatno-repeat;
     
}
/*点input被选中后 同步背景选择*/
.main > input.selectImg-01:checked ~ .back,
.main > .back > div > span:nth-child(1){
    backgroundurl(../images/1.jpg) no-repeat;
}
.main > input.selectImg-02:checked ~ .back,
.main > .back > div > span:nth-child(2) {
    backgroundurl(../images/2.jpg) no-repeat;
}
.main > input.selectImg-03:checked ~ .back,
.main > .back > div > span:nth-child(3) {
    backgroundurl(../images/3.jpg) no-repeat;
}
.main > input.selectImg-04:checked ~ .back,
.main > .back > div > span:nth-child(4) {
    backgroundurl(../images/4.jpg) no-repeat;
}
 
/*每个div下的span做平移*/
.back > div:first-of-type > span {
    background-position0px 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-index10;
}


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
妮可妮可妮_ 2018-05-30 15:20:15

http://img1.sycdn.imooc.com//climg/5b0e50230001798105660255.jpg

因为这两个设置起了冲突,上面的权重要比下面的高,所以没有生效

  • 提问者 qq_ToutAn諾尘_0 #1
    background 包含他所有的子属性吗,比如 background-repeat background-position 等等。。
    2018-06-01 18:40:16
  • 提问者 qq_ToutAn諾尘_0 #2
    怎么才能避免这种问题,导致因为属性权重低 而被覆盖的问题
    2018-06-01 18:42:59
  • 妮可妮可妮_ 回复 提问者 qq_ToutAn諾尘_0 #3
    background 简写属性在一个声明中设置所有的背景属性。 可以设置如下属性: background-color background-position background-size background-repeat background-origin background-clip background-attachment background-image 如何避免出现属性权重低被覆盖的问题就需要同学自己总结出自己的代码习惯啦~比如在设置统一样式时,可以选择权重较小的设置方式,也可以在控制台检查是否有出现因为权重问题没有作用上的设置.
    2018-06-01 18:53:08
提问者 qq_ToutAn諾尘_0 2018-05-30 13:22:00

http://img1.sycdn.imooc.com//climg/5b0e347f0001cb3009100819.jpgF12 background-position 被划掉了,不生效

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码