CSS滑块没有经过第五张幻灯片

时间:2015-05-28 19:52:32

标签: html css css3 slideshow

我正在使用的CSS滑块上只有五个单选按钮/幻灯片。

当我尝试添加更多幻灯片时,滑块无法滚动到新幻灯片。

我哪里错了?

我在CSS中最多添加了15个幻灯片实例,但目前只需要10张幻灯片。

我还想在滑块中添加一个滑块,我的代码会受到怎样的影响?我不知道如何处理它。

我的代码:

/* Common styles and resets */

.dotstyle label {
	position: relative;
	display: inline-block;
	margin: 0;
	padding: 0;
	list-style: none;
	cursor: default;
	-webkit-touch-callout: none;
	-webkit-user-select: none;
	-khtml-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
}

.dotstyle label {
	position: relative;
	display: block;
	float: left;
	margin: 0 16px;
	width: 16px;
	height: 16px;
	cursor: pointer;
	opacity: 0.15;
}

.dotstyle label a {
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	outline: none;
	border-radius: 50%;
	background-color: #fff;
	background-color: rgba(255, 255, 255, 0.3);
	text-indent: -999em; /* make the text accessible to screen readers */
	cursor: pointer;
	position: absolute;
}

.dotstyle label a:focus {
	outline: none;
}

/* Tooltip */

.dotstyle-tooltip label {
	border: 2px solid #fff;
	border-radius: 50%;
	z-index: 1;
	-webkit-transition: border-color 0.3s ease;
	transition: border-color 0.3s ease;
}

.dotstyle-tooltip label a {
	top: auto;
	bottom: 250%;
	left: 50%;
	visibility: hidden;
	padding: 0 10px;
	width: auto;
	height: auto;
	border-radius: 0;
	background-color: #e19a28;
	color: #fff;
	text-indent: 0;
	line-height: 2;
	opacity: 0;
	-webkit-transform: translateX(-50%) translateY(-50%);
	transform: translateX(-50%) translateY(-50%);
	-webkit-transition: -webkit-transform 0.3s ease, opacity 0.3s ease, visibility 0s 0.3s ease;
	transition: transform 0.3s ease, opacity 0.3s ease, visibility 0s 0.3s ease;
}

.dotstyle-tooltip label a::after { /* http: //cssarrowplease.com/ */
	position: absolute;
	left: 50%;
	margin-left: -10px;
	width: 0;
	height: 0;
	border: solid transparent;
	border-width: 10px;
	border-color: transparent;
	border-top-color: #e19a28;
	content: '';
	pointer-events: none;
	top: 99%;
	-webkit-backface-visibility: hidden;
	backface-visibility: hidden;
	-webkit-transition: opacity 0.3s ease;
	transition: opacity 0.3s ease;
}

.no-touch .dotstyle-tooltip label:hover a,
.dotstyle-tooltip label.current a {
	z-index: 100;
	visibility: visible;
	opacity: 1;
	-webkit-transform: translateX(-50%) translateY(0%);
	transform: translateX(-50%) translateY(0%);
	-webkit-transition: -webkit-transform 0.3s ease, opacity 0.3s ease;
	transition: transform 0.3s ease, opacity 0.3s ease;
	opacity: 1 !important;
}

.dotstyle-tooltip label.current {
	border-color: #c44d48;
}

.dotstyle-tooltip label:hover {
	z-index: 100;
	opacity: 0.65 !important;
}

.no-touch .dotstyle-tooltip label:hover label.current a {
	opacity: 0.2;
}

.dotstyle-tooltip label.current:hover a {
	opacity: 1;
}

#slide1:checked ~ .dotstyle-tooltip label:nth-child(1), #slide2:checked ~ .dotstyle-tooltip label:nth-child(2), #slide3:checked ~ .dotstyle-tooltip label:nth-child(3), #slide4:checked ~ .dotstyle-tooltip label:nth-child(4), #slide5:checked ~ .dotstyle-tooltip label:nth-child(5), #slide6:checked ~ .dotstyle-tooltip label:nth-child(6), #slide7:checked ~ .dotstyle-tooltip label:nth-child(7), #slide8:checked ~ .dotstyle-tooltip label:nth-child(8), #slide9:checked ~ .dotstyle-tooltip label:nth-child(9), #slide10:checked ~ .dotstyle-tooltip label:nth-child(10),#slide11:checked ~ .dotstyle-tooltip label:nth-child(11), #slide12:checked ~ .dotstyle-tooltip label:nth-child(12), #slide13:checked ~ .dotstyle-tooltip label:nth-child(13), #slide14:checked ~ .dotstyle-tooltip label:nth-child(14), #slide15:checked ~ .dotstyle-tooltip label:nth-child(15) {
	 border: 2px solid #000;
    border-radius: 50%;
    transition: border-color 0.3s ease 0s;
    z-index: 1;
}

article {
  display: block;
  overflow-y: hidden;
}

.container-slide {
  overflow-x: hidden;
  position: relative;
}

#slider {
	text-align: center;
	margin: 0 auto;
}

.catch {
	display: block;
	height: 0;
	overflow: hidden;
}

#description {
	margin: 25px auto;
	text-align: left;
	max-width: 650px;
	padding: 0 25px;
}

.respond {
	margin: 0 auto;
	max-width: 370px;
}

/* Slider Setup */

#slider>input {
	display: none;
}

#slide1:checked ~ #slides .inner { margin-left:0; }
#slide2:checked ~ #slides .inner { margin-left:-100%; }
#slide3:checked ~ #slides .inner { margin-left:-200%; }
#slide4:checked ~ #slides .inner { margin-left:-300%; }
#slide5:checked ~ #slides .inner { margin-left:-400%; }
#slide6:checked ~ #slides .inner { margin-left:-500%; }
#slide7:checked ~ #slides .inner { margin-left:-600%; }
#slide8:checked ~ #slides .inner { margin-left:-700%; }
#slide9:checked ~ #slides .inner { margin-left:-800%; }
#slide10:checked ~ #slides .inner { margin-left:-900%; }
#slide11:checked ~ #slides .inner { margin-left:-1000%; }
#slide12:checked ~ #slides .inner { margin-left:-1100%; }
#slide13:checked ~ #slides .inner { margin-left:-1200%; }
#slide14:checked ~ #slides .inner { margin-left:-1300%; }
#slide15:checked ~ #slides .inner { margin-left:-1400%; }


#overflow {
	width: 100%;
	overflow: hidden;
}

article img {
	width: 100%;
}

#slides .inner {
	width: 500%;
	line-height: 0;
}

#slides article {
	width: 20%;
	float: left;
}

/* slider Styling */

/* Control Setup */

#controls {
	margin: -25% 0 0 0;
	width: 100%;
	height: 50px;
}

#controls li { 
	display: none;
	width: 50px;
	height: 50px;
	opacity: 0.3;
}

#active {
	height: 100%;
    margin-left: auto;
    margin-right: auto;
    margin-top: 2%;
    text-align: center;
    width: 515px;
}

#active label {
	-webkit-border-radius: 15px;
	-moz-border-radius: 15px;
	border-radius: 15px;
	display: inline-block;
	width: 15px;
	height: 15px;
	background: #bbb;
}

#active label:hover {
	background: #ccc;
	border-color: #777 !important;
}

#controls label:hover {
	opacity: 0.8;
}

#slide1:checked ~ #controls li:nth-child(2), 
#slide2:checked ~ #controls li:nth-child(3), 
#slide3:checked ~ #controls li:nth-child(4), 
#slide4:checked ~ #controls li:nth-child(5),
#slide5:checked ~ #controls li:nth-child(6),
#slide6:checked ~ #controls li:nth-child(7),
#slide7:checked ~ #controls li:nth-child(8), 
#slide8:checked ~ #controls li:nth-child(9), 
#slide9:checked ~ #controls li:nth-child(10),
#slide10:checked ~ #controls li:nth-child(11),
#slide11:checked ~ #controls li:nth-child(12),
#slide12:checked ~ #controls li:nth-child(13), 
#slide13:checked ~ #controls li:nth-child(14), 
#slide14:checked ~ #controls li:nth-child(15), 
#slide15:checked ~ #controls li:nth-child(1) {
	background: url('next.png') no-repeat;
	float: right;
	margin: 0 -70px 0 0;
	display: block;
}


#slide1:checked ~ #controls li:nth-child(15),
#slide2:checked ~ #controls li:nth-child(1),
#slide3:checked ~ #controls li:nth-child(2),
#slide4:checked ~ #controls li:nth-child(3),
#slide5:checked ~ #controls li:nth-child(4),
#slide6:checked ~ #controls li:nth-child(5),
#slide7:checked ~ #controls li:nth-child(6),
#slide8:checked ~ #controls li:nth-child(7),
#slide9:checked ~ #controls li:nth-child(8),
#slide10:checked ~ #controls li:nth-child(9),
#slide11:checked ~ #controls li:nth-child(10),
#slide12:checked ~ #controls li:nth-child(11),
#slide13:checked ~ #controls li:nth-child(12),
#slide14:checked ~ #controls li:nth-child(13),
#slide15:checked ~ #controls li:nth-child(14) {
	background: url('prev.png') no-repeat;
	float: left;
	margin: 0 0 0 -70px;
	display: block;
}

#slide1:checked ~ #active label:nth-child(1),
#slide2:checked ~ #active label:nth-child(2),
#slide3:checked ~ #active label:nth-child(3),
#slide4:checked ~ #active label:nth-child(4),
#slide5:checked ~ #active label:nth-child(5),
#slide6:checked ~ #active label:nth-child(6),
#slide7:checked ~ #active label:nth-child(7),
#slide8:checked ~ #active label:nth-child(8),
#slide9:checked ~ #active label:nth-child(9),
#slide10:checked ~ #active label:nth-child(10),
#slide11:checked ~ #active label:nth-child(11),
#slide12:checked ~ #active label:nth-child(12),
#slide13:checked ~ #active label:nth-child(13),
#slide14:checked ~ #active label:nth-child(14)
#slide15:checked ~ #active label:nth-child(15) {
	background: none repeat scroll 0 0 #e19a28;
    border-color: #e19a28 !important;
    opacity: 1 !important;
}

/* Info Box */

.info {
	line-height: 20px;
	/*margin: 0 0 -150%;*/
	position: absolute;
	font-style: italic;
	padding: 30px 30px;
	opacity: 0;
	color: #000;
	text-align: left;
}

.info h3 {
	color: #333;
	margin: 0 0 5px;
	font-weight: normal;
	font-size: 22px;
	font-style: normal;
}

/* slider Styling */

#slides {
	height: 350px;
	padding: 1%;
	background: none repeat scroll 0 0 #353535;
}


/* Animation */

#slides .inner {
	-webkit-transform: translateZ(0);
	-webkit-transition: all 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); 
	-moz-transition: all 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); 
    -ms-transition: all 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); 
     -o-transition: all 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); 
        transition: all 800ms cubic-bezier(0.770, 0.000, 0.175, 1.000); /* easeInOutQuart */

	-webkit-transition-timing-function: cubic-bezier(0.770, 0.000, 0.175, 1.000); 
	-moz-transition-timing-function: cubic-bezier(0.770, 0.000, 0.175, 1.000); 
    -ms-transition-timing-function: cubic-bezier(0.770, 0.000, 0.175, 1.000); 
     -o-transition-timing-function: cubic-bezier(0.770, 0.000, 0.175, 1.000); 
        transition-timing-function: cubic-bezier(0.770, 0.000, 0.175, 1.000); /* easeInOutQuart */
}

#slider {
	-webkit-transform: translateZ(0);
	-webkit-transition: all 0.5s ease-out;
	-moz-transition: all 0.5s ease-out;
	-o-transition: all 0.5s ease-out;
	transition: all 0.5s ease-out;
}

#controls li{
	-webkit-transform: translateZ(0);
	-webkit-transition: opacity 0.2s ease-out;
	-moz-transition: opacity 0.2s ease-out;
	-o-transition: opacity 0.2s ease-out;
	transition: opacity 0.2s ease-out;
}

#slide1:checked ~ #slides article:nth-child(1) .info,
#slide2:checked ~ #slides article:nth-child(2) .info,
#slide3:checked ~ #slides article:nth-child(3) .info,
#slide4:checked ~ #slides article:nth-child(4) .info,
#slide5:checked ~ #slides article:nth-child(5) .info,
#slide6:checked ~ #slides article:nth-child(6) .info,
#slide7:checked ~ #slides article:nth-child(7) .info,
#slide8:checked ~ #slides article:nth-child(8) .info,
#slide9:checked ~ #slides article:nth-child(9) .info,
#slide10:checked ~ #slides article:nth-child(10) .info,
#slide11:checked ~ #slides article:nth-child(11) .info,
#slide12:checked ~ #slides article:nth-child(12) .info,
#slide13:checked ~ #slides article:nth-child(13) .info,
#slide14:checked ~ #slides article:nth-child(14) .info,
#slide15:checked ~ #slides article:nth-child(15) .info {
	opacity: 1;
	-webkit-transition: all 1s ease-out 0.6s;
	-moz-transition: all 1s ease-out 0.6s;
	-o-transition: all 1s ease-out 0.6s;
	transition: all 1s ease-out 0.6s;
}

.info, #controls, #slides, #active, #active li, .info h3, .desktop, .tablet, .mobile {
	-webkit-transform: translateZ(0);
	-webkit-transition: all 0.5s ease-out;
	-moz-transition: all 0.5s ease-out;
	-o-transition: all 0.5s ease-out;
	transition: all 0.5s ease-out;
}




/* Responsive Styling */

/* Tablet */

#tablet:checked ~ #slider #controls {
	margin: -25% 0 0 12%;
	width: 76%;
	height: 50px;
}

#tablet:checked ~ #slider #controls li {
	-moz-transform: scale(0.8);
	-webkit-transform: scale(0.8);
	-o-transform: scale(0.8);
	-ms-transform: scale(0.8);
	transform: scale(0.8);
}

#tablet:checked  ~ #slider #slides, #mobile:checked  ~ #slider #slides {
	padding: 1% 0;
}

#tablet:checked ~ #slider #active {
	margin: 22% 0 0;
}

@media only screen and (max-width: 850px) and (min-width: 450px) {

	#slider #controls {
		margin: -25% 0 0 15%;
		width: 70%;
		height: 50px;
	}

	#slider #controls li {
		-moz-transform: scale(0.8);
		-webkit-transform: scale(0.8);
		-o-transform: scale(0.8);
		-ms-transform: scale(0.8);
		transform: scale(0.8);
	}

	#slider #slides {
		padding: 1% 0;
	}

	#slider #active {
		margin: 22% 0 0;
	}

}

/* Mobile */

#mobile:checked ~ #slider #controls {
	margin: -28% 0 0 24%;
	width: 50%;
	height: 50px;
}

#mobile:checked ~ #slider #active {
	margin: 23% 0 0;
}

#mobile:checked ~ #slider #slides .info {
	opacity: 0 !important;
}

#mobile:checked ~ #slider #controls li {
	-moz-transform: scale(0.6);
	-webkit-transform: scale(0.6);
	-o-transform: scale(0.6);
	-ms-transform: scale(0.6);
	transform: scale(0.6);
}


@media only screen and (max-width: 450px) {

	#slider #controls {
		margin: -28% 0 0 24%;
		width: 50%;
		height: 50px;
	}

	#slider #active {
		margin: 23% 0 0;
	}

	#slider #slides {
		padding: 1% 0;
	}

	#slider #slides .info {
		opacity: 0 !important;
	}

	#slider #controls li {
		-moz-transform: scale(0.6);
		-webkit-transform: scale(0.6);
		-o-transform: scale(0.6);
		-ms-transform: scale(0.6);
		transform: scale(0.6);
	}

}


@media only screen and (min-width: 850px) {

	.container-slide {
		padding: 0 80px;
	}
}
<div class="container-slide">
				
                
              
<article id="slider">
		
	
		<!-- Slider Setup -->
	
		<input selected="false" name="slider" id="slide1" type="radio">
		<input selected="false" name="slider" id="slide2" type="radio">
		<input selected="false" name="slider" id="slide3" type="radio">
		<input selected="false" name="slider" id="slide4" type="radio">
		<input selected="false" name="slider" id="slide5" type="radio">
        <input selected="false" name="slider" id="slide6" type="radio">
        <input selected="false" name="slider" id="slide7" type="radio">
        <input selected="false" name="slider" id="slide8" type="radio">
        <input checked="checked" selected="false" name="slider" id="slide9" type="radio">
        <input selected="true" name="slider" id="slide10" type="radio">
	
	
		<!-- The Slider -->
		
		<div id="slides">
		
			<div id="overflow">
			
				<div class="inner">
				
					<article>
						<div class="info"><h3>Cloud Dragon</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="CouldDragonByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Mountain Fort</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="MountainFortByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Mountain Outpost</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="MountainOutpostByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Cliffs</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="CliffsByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Hill Fort</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="HillFortByBjzaba.png">
					</article>
                    
                    <article>
						<div class="info"><h3>Cloud Dragon</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="CouldDragonByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Mountain Fort</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="MountainFortByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Mountain Outpost</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="MountainOutpostByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Cliffs</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="CliffsByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Hill Fort</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="HillFortByBjzaba.png">
					</article>
                    
                    <article>
						<div class="info"><h3>Cloud Dragon</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="CouldDragonByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Mountain Fort</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="MountainFortByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Mountain Outpost</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="MountainOutpostByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Cliffs</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="CliffsByBjzaba.png">
					</article>
					
					<article>
						<div class="info"><h3>Hill Fort</h3> by <a href="http://voyager3.tumblr.com/">Brendan Zabarauskas</a></div>
						<img src="HillFortByBjzaba.png">
					</article>
					
				</div> <!-- .inner -->
				
			</div> <!-- #overflow -->
		
		</div> <!-- #slides -->
	
	
		<!-- Controls and Active Slide Display -->
        
        <div id="controls-slide">
						<label for="slide1"></label>
						<label for="slide2"></label>
                        <label for="slide3"></label>
                        <label for="slide4"></label>
                        <label for="slide5"></label>
                        <label for="slide6"></label>
						<label for="slide7"></label>
                        <label for="slide8"></label>
                        <label for="slide9"></label>
                        <label for="slide10"></label>
				</div>
		
		<div id="active" class="dotstyle dotstyle-tooltip">

						<label for="slide1"><a>Sean</a></label>
						<label for="slide2"><a>Richard</a></label>
                        <label for="slide3"><a>Anton</a></label>
                        <label for="slide4"><a>Travis</a></label>
                        <label for="slide5"><a>Matt</a></label>
                        <label for="slide6"><a>Roxy</a></label>
						<label for="slide7"><a>David</a></label>
                        <label for="slide8"><a>Charlie</a></label>
                        <label for="slide9"><a>Phil</a></label>
                        <label for="slide10"><a>Mike</a></label>
			
		</div> <!-- #active -->
	
	</article> <!-- #slider -->
        
        
        
        
    
</div>

1 个答案:

答案 0 :(得分:1)

这是因为你的这两种风格:

#slides .inner {
    width: 500%;
}

#slides article {
    width: 20%;
}

这些宽度设置为仅使用5张幻灯片。 .inner宽度应该是(100 * numberOfSlides),article应该是(100 / numberOfSlides),以便全部适合一行。您只看到5,因为第5个之后的所有其他幻灯片都在第5个之后包装。

请参见适用于15张幻灯片的fiddle。唯一的更新是:

#slides .inner {
    width: 1500%;
}

#slides article {
    width: 6.6%;
}