有没有办法可以使用CSS3和HTML创建图像滑块,
但不使用任何HTML input
(无线电)元素,没有JavaScript?
我有一个大规模的搜索会话,发现很接近并运行良好的东西,但是使用HTML无线电输入.
(...因为你不允许使用input radio
元素来维持活动状态......)
还有另一种方法可以使用伪在纯CSS(3)中创建一个滑动库. :target
:target
成为id="foo"
由具有URI片段(哈希)的点击锚引用的元素href="#foo"
在CSS中,使用:target
伪可以使用~
(通用同级选择器)将树下引用到其他同级元素,并且可以像往常一样进一步访问其子元素(幻灯片,按钮等).
提示:如果您不喜欢图库中的"功能" 弄乱您的URL片段(浏览器返回按钮触发图库幻灯片而不是导航历史记录!),您可以随时对其进行沙盒化 - 将您的图库文件调用为.
html, body{height:100%;}
body{font:15px/1 sans-serif; margin:0;}
/*
RESPONSIVE CSS3 SLIDE CAROUSEL GALLERY
http://stackoverflow.com/a/34696029/383904
*/
.CSSgal{
position: relative;
overflow: hidden;
height: 100%; /* Or set a fixed height */
}
/* SLIDER */
.CSSgal .slider{
height: 100%;
white-space: nowrap;
font-size: 0;
transition: 0.8s;
}
/* SLIDES */
.CSSgal .slider > *{
font-size: 1rem;
display: inline-block;
vertical-align: top;
height: 100%;
width: 100%;
background: none 50% no-repeat;
background-size: cover;
}
/* PREV/NEXT, CONTAINERS & ANCHORS */
.CSSgal .prevNext{
position: absolute;
z-index: 1;
top: 50%;
width: 100%;
height: 0;
}
.CSSgal .prevNext > div+div{
visibility: hidden; /* Hide all but first P/N container */
}
.CSSgal .prevNext a{
background: #fff;
position: absolute;
width: 40px;
height: 40px;
line-height: 40px;
text-align: center;
opacity: 0.7;
text-decoration: none;
-webkit-transform: translateY( -50% );
transform: translateY( -50% );
}
.CSSgal .prevNext a:hover{
opacity: 1;
}
.CSSgal .prevNext a+a{
right: 0px;
}
/* NAVIGATION */
.CSSgal .bullets{
position: absolute;
z-index: 2;
bottom: 0;
padding: 10px 0;
width: 100%;
text-align: center;
}
.CSSgal .bullets > a{
display: inline-block;
width: 20px;
height: 20px;
line-height: 20px;
text-decoration: none;
text-align: center;
border-radius: 50%;
background: rgba(255,255,255,1);
}
.CSSgal .bullets > a+a{
background: rgba(255,255,255,0.5); /* Dim all but first */
}
.CSSgal .bullets > a:hover{
background: rgba(0,255,255,0.9);
}
/* ACTIVE NAVIGATION ANCHOR */
.CSSgal >s:target ~ .bullets >* { background: rgba(255,255,255,0.5); }
#s1:target ~ .bullets >*:nth-child(1){ background: rgba(255,255,255, 1); }
#s2:target ~ .bullets >*:nth-child(2){ background: rgba(255,255,255, 1); }
#s3:target ~ .bullets >*:nth-child(3){ background: rgba(255,255,255, 1); }
#s4:target ~ .bullets >*:nth-child(4){ background: rgba(255,255,255, 1); }
/* PREV/NEXT CONTAINERS VISIBILITY */
.CSSgal >s:target ~ .prevNext >* { visibility: hidden; }
#s1:target ~ .prevNext >*:nth-child(1){ visibility: visible; }
#s2:target ~ .prevNext >*:nth-child(2){ visibility: visible; }
#s3:target ~ .prevNext >*:nth-child(3){ visibility: visible; }
#s4:target ~ .prevNext >*:nth-child(4){ visibility: visible; }
/* SLIDER ANIMATION POSITIONS */
#s1:target ~ .slider{ transform: translateX( 0%); -webkit-transform: translateX( 0%); }
#s2:target ~ .slider{ transform: translateX(-100%); -webkit-transform: translateX(-100%); }
#s3:target ~ .slider{ transform: translateX(-200%); -webkit-transform: translateX(-200%); }
#s4:target ~ .slider{ transform: translateX(-300%); -webkit-transform: translateX(-300%); }