HTML和CSS Carousel问题

时间:2017-03-23 14:55:11

标签: html css

我在网上找到了使用HTML和CSS创建轮播的代码。我设法再添加2张幻灯片(幻灯片4和5),但在这两张幻灯片上,左箭头指向右侧。我无法弄清楚我做错了什么。有人能指出我正确的方向吗?什么都有帮助,谢谢。



<style>

.carousel {
    border-style:solid;
    border-width:1px;
    border-color:rgba(0, 0, 0, 0.05);
    box-shadow: 0px 1px 6px rgba(0, 0, 0, 0.1);
    widht:100%;
    height:250px;
}

.carousel-inner {
    position: relative;
    overflow: hidden;
    width: 100%;
    height:250px;
}

.carousel-open:checked + .carousel-item {
    position: absolute;
    opacity: 100;
    background-color:white;
    width:100%;
    height:250px;
}

.carousel-item {
    position: absolute;
    opacity: 0;
    padding-top:10px;
    text-align:center;
}

.carousel-control {
    background: rgba(0, 0, 0, 0);
    border-radius: 50%;
    color:#008c6c;
    cursor: pointer;
    display: none;
    font-size: 30px;
    height: 40px;
    line-height: 35px;
    position: absolute;
    top: 50%;
    -webkit-transform: translate(0, -50%);
    cursor: pointer;
    -ms-transform: translate(0, -50%);
    transform: translate(0, -50%);
    text-align: center;
    width: 40px;
    z-index: 10;
}

.carousel-control.prev {
    left: 2%;
}

.carousel-control.next {
    right: 2%;
}

.carousel-control:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #008c6c;
}

#carousel-1:checked ~ .control-1,
#carousel-2:checked ~ .control-2,
#carousel-3:checked ~ .control-3,
#carousel-4:checked ~ .control-4,
#carousel-5:checked ~ .control-5{
    display: block;
}

.carousel-indicators {
    margin: 0;
    padding: 0;
    position: absolute;
    bottom: 2px;
    left: 0;
    right: 0;
    text-align: center;
}

.carousel-indicators li {
    display: inline-block;
    margin: 0 5px;
}

.carousel-bullet {
    color: rgba(0, 0, 0, 0.05);
    cursor: pointer;
    font-size: 25px;
}

.carousel-bullet:hover {
    color: rgba(0, 0, 0, 0.1);
}

#carousel-1:checked ~ .control-1 ~ .carousel-indicators li:nth-child(1) .carousel-bullet,
#carousel-2:checked ~ .control-2 ~ .carousel-indicators li:nth-child(2) .carousel-bullet,
#carousel-3:checked ~ .control-3 ~ .carousel-indicators li:nth-child(3) .carousel-bullet,
#carousel-4:checked ~ .control-4 ~ .carousel-indicators li:nth-child(4) .carousel-bullet,
#carousel-5:checked ~ .control-5 ~ .carousel-indicators li:nth-child(5) .carousel-bullet{
    color: #008c6c;
}

#title {
    width: 100%;
    position: absolute;
    padding: 0px;
    margin: 0px auto;
    text-align: center;
    font-size: 27px;
    color: rgba(255, 255, 255, 1);
    font-family: 'Open Sans', sans-serif;
    z-index: 9999;
    text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.33), -1px 0px 2px rgba(255, 255, 255, 0);
}
</style>
&#13;
<div class="carousel"> 
   <div class="carousel-inner"> 
      <input name="carousel" class="carousel-open" id="carousel-1" aria-hidden="true" type="radio" hidden="true" Checked/>
      <div class="carousel-item"> 

<img src="/"/>

      </div> 
      <input name="carousel" class="carousel-open" id="carousel-2" aria-hidden="true" type="radio" hidden="true"/> 
      <div class="carousel-item"> 
         <h1>2</h1> 
         <p> Content here for page two.</p> 
      </div> 
      <input name="carousel" class="carousel-open" id="carousel-3" aria-hidden="true" type="radio" hidden="true"/> 
      <div class="carousel-item"> 
         <h1>3</h1> 
         <p> Content here for page three.</p> 
      </div> 
      <input name="carousel" class="carousel-open" id="carousel-4" aria-hidden="true" type="radio" hidden="true"/> 
      <div class="carousel-item"> 
         <h1>4</h1> 
         <p> Content here for page four.</p> 
      </div>
      <input name="carousel" class="carousel-open" id="carousel-5" aria-hidden="true" type="radio" hidden="true"/> 
      <div class="carousel-item"> 
         <h1>5</h1> 
         <p> Content here for page five.</p> 
      </div> 
      <label class="carousel-control prev control-1" for="carousel-5">‹</label>
      <label class="carousel-control next control-1" for="carousel-2">›</label>
      <label class="carousel-control prev control-2" for="carousel-1">‹</label>
      <label class="carousel-control next control-2" for="carousel-3">›</label>
      <label class="carousel-control prev control-3" for="carousel-2">‹</label>
      <label class="carousel-control next control-3" for="carousel-4">›</label> 
      <label class="carousel-control prev control-4" for="carousel-3">›</label>
      <label class="carousel-control next control-4" for="carousel-5">›</label>
      <label class="carousel-control prev control-5" for="carousel-4">›</label>
      <label class="carousel-control next control-5" for="carousel-1">›</label>
      <ol class="carousel-indicators"> 
         <li> 
            <label class="carousel-bullet" for="carousel-1">•</label> </li> 
         <li> 
            <label class="carousel-bullet" for="carousel-2">•</label> </li> 
         <li> 
            <label class="carousel-bullet" for="carousel-3">•</label> </li> 
         <li> 
            <label class="carousel-bullet" for="carousel-4">•</label> </li> 
         <li> 
            <label class="carousel-bullet" for="carousel-5">•</label> </li> 
      </ol> 
   </div> 
</div>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:1)

看看这一行:

<label class="carousel-control prev control-1" for="carousel-5">‹</label>
<label class="carousel-control next control-1" for="carousel-2">›</label>
<label class="carousel-control prev control-2" for="carousel-1">‹</label>
<label class="carousel-control next control-2" for="carousel-3">›</label>
<label class="carousel-control prev control-3" for="carousel-2">‹</label>
<label class="carousel-control next control-3" for="carousel-4">›</label> 
<label class="carousel-control prev control-4" for="carousel-3">›</label>
<label class="carousel-control next control-4" for="carousel-5">›</label>
<label class="carousel-control prev control-5" for="carousel-4">›</label>
<label class="carousel-control next control-5" for="carousel-1">›</label>
  

标签... for =&#34; carousel-1&#34;这是你的错;)

以下是它的样子:

&#13;
&#13;
<style>

.carousel {
    border-style:solid;
    border-width:1px;
    border-color:rgba(0, 0, 0, 0.05);
    box-shadow: 0px 1px 6px rgba(0, 0, 0, 0.1);
    widht:100%;
    height:250px;
}

.carousel-inner {
    position: relative;
    overflow: hidden;
    width: 100%;
    height:250px;
}

.carousel-open:checked + .carousel-item {
    position: absolute;
    opacity: 100;
    background-color:white;
    width:100%;
    height:250px;
}

.carousel-item {
    position: absolute;
    opacity: 0;
    padding-top:10px;
    text-align:center;
}

.carousel-control {
    background: rgba(0, 0, 0, 0);
    border-radius: 50%;
    color:#008c6c;
    cursor: pointer;
    display: none;
    font-size: 30px;
    height: 40px;
    line-height: 35px;
    position: absolute;
    top: 50%;
    -webkit-transform: translate(0, -50%);
    cursor: pointer;
    -ms-transform: translate(0, -50%);
    transform: translate(0, -50%);
    text-align: center;
    width: 40px;
    z-index: 10;
}

.carousel-control.prev {
    left: 2%;
}

.carousel-control.next {
    right: 2%;
}

.carousel-control:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #008c6c;
}

#carousel-1:checked ~ .control-1,
#carousel-2:checked ~ .control-2,
#carousel-3:checked ~ .control-3,
#carousel-4:checked ~ .control-4,
#carousel-5:checked ~ .control-5{
    display: block;
}

.carousel-indicators {
    margin: 0;
    padding: 0;
    position: absolute;
    bottom: 2px;
    left: 0;
    right: 0;
    text-align: center;
}

.carousel-indicators li {
    display: inline-block;
    margin: 0 5px;
}

.carousel-bullet {
    color: rgba(0, 0, 0, 0.05);
    cursor: pointer;
    font-size: 25px;
}

.carousel-bullet:hover {
    color: rgba(0, 0, 0, 0.1);
}

#carousel-1:checked ~ .control-1 ~ .carousel-indicators li:nth-child(1) .carousel-bullet,
#carousel-2:checked ~ .control-2 ~ .carousel-indicators li:nth-child(2) .carousel-bullet,
#carousel-3:checked ~ .control-3 ~ .carousel-indicators li:nth-child(3) .carousel-bullet,
#carousel-4:checked ~ .control-4 ~ .carousel-indicators li:nth-child(4) .carousel-bullet,
#carousel-5:checked ~ .control-5 ~ .carousel-indicators li:nth-child(5) .carousel-bullet{
    color: #008c6c;
}

#title {
    width: 100%;
    position: absolute;
    padding: 0px;
    margin: 0px auto;
    text-align: center;
    font-size: 27px;
    color: rgba(255, 255, 255, 1);
    font-family: 'Open Sans', sans-serif;
    z-index: 9999;
    text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.33), -1px 0px 2px rgba(255, 255, 255, 0);
}
</style>
&#13;
<div class="carousel"> 
   <div class="carousel-inner"> 
      <input name="carousel" class="carousel-open" id="carousel-1" aria-hidden="true" type="radio" hidden="true" Checked/>
      <div class="carousel-item"> 

<img src="/"/>

      </div> 
      <input name="carousel" class="carousel-open" id="carousel-2" aria-hidden="true" type="radio" hidden="true"/> 
      <div class="carousel-item"> 
         <h1>2</h1> 
         <p> Content here for page two.</p> 
      </div> 
      <input name="carousel" class="carousel-open" id="carousel-3" aria-hidden="true" type="radio" hidden="true"/> 
      <div class="carousel-item"> 
         <h1>3</h1> 
         <p> Content here for page three.</p> 
      </div> 
      <input name="carousel" class="carousel-open" id="carousel-4" aria-hidden="true" type="radio" hidden="true"/> 
      <div class="carousel-item"> 
         <h1>4</h1> 
         <p> Content here for page four.</p> 
      </div>
      <input name="carousel" class="carousel-open" id="carousel-5" aria-hidden="true" type="radio" hidden="true"/> 
      <div class="carousel-item"> 
         <h1>5</h1> 
         <p> Content here for page five.</p> 
      </div> 
      <label class="carousel-control prev control-1" for="carousel-5">‹</label>
      <label class="carousel-control next control-1" for="carousel-2">›</label>
      <label class="carousel-control prev control-2" for="carousel-1">‹</label>
      <label class="carousel-control next control-2" for="carousel-3">›</label>
      <label class="carousel-control prev control-3" for="carousel-2">‹</label>
      <label class="carousel-control next control-3" for="carousel-4">›</label> 
      <label class="carousel-control prev control-4" for="carousel-3">‹</label>
      <label class="carousel-control next control-4" for="carousel-5">›</label>
      <label class="carousel-control prev control-5" for="carousel-4">‹</label>
      <label class="carousel-control next control-5" for="carousel-1">›</label>
      <ol class="carousel-indicators"> 
         <li> 
            <label class="carousel-bullet" for="carousel-1">•</label> </li> 
         <li> 
            <label class="carousel-bullet" for="carousel-2">•</label> </li> 
         <li> 
            <label class="carousel-bullet" for="carousel-3">•</label> </li> 
         <li> 
            <label class="carousel-bullet" for="carousel-4">•</label> </li> 
         <li> 
            <label class="carousel-bullet" for="carousel-5">•</label> </li> 
      </ol> 
   </div> 
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

为此,你可能会把头撞到墙上,但是你只是将一个小错误复制粘贴到新的旋转木马标签上。

这是正确的:

<label class="carousel-control prev control-4" for="carousel-3">‹</label>
<label class="carousel-control next control-4" for="carousel-5">›</label>
<label class="carousel-control prev control-5" for="carousel-4">‹</label>
<label class="carousel-control next control-5" for="carousel-1">›</label>

左边有右箭头,因为左边有向右箭头:

<label class="carousel-control prev control-4" for="carousel-3">›(not left)</label>
<label class="carousel-control next control-4" for="carousel-5">›</label>
<label class="carousel-control prev control-5" for="carousel-4">›(not left)</label>
<label class="carousel-control next control-5" for="carousel-1">›</label>

答案 2 :(得分:0)

对于幻灯片4和5,您使用了“>”两次。