将纯CSS轮播保留在固定位置

问题描述 投票:0回答:1

我有许多链接可在网页上显示,并且所有链接都指向弹出画廊。每当我单击链接时,它都会跳到网页的结尾,但轮播显示在页面顶部。

单击链接以打开它时,我试图将纯CSS轮播保留在同一位置。

此外,当您在轮播中单击“下一步”按钮时,它也会跳到底部,这是不应该的。

这是我已经拥有的。

有什么想法吗?

谢谢

 .lightbox__slide img {
	 position: absolute;
	 z-index: 30;
	 max-width: 90%;
	 max-height: 80%;
	 top: 50%;
	 left: 50%;
	 transform: translate(-50%, -50%);
	 animation-name: hide;
	 animation-duration: 0.5s;
	 animation-iteration-count: 1;
	 animation-direction: linear;
	 animation-fill-mode: forwards;
}
 .lightbox__slide:target .btn { display: block; }
 .lightbox__slide:target img {
	 opacity: 0;
	 animation-name: show;
	 animation-duration: 0.5s;
	 animation-iteration-count: 1;
	 animation-direction: linear;
	 animation-fill-mode: forwards;
}
 .lightbox__slide:target ~ .lightbox__bg {
	 position: relative;
	 background:white;
	 opacity: 0.6;
	 top: 0;
	 left: 0;
	 width: 100%;
	 height: 100%;
	 z-index: 1;
}

 @-webkit-keyframes show { 0% { opacity: 0; } 100% { opacity: 1; } }
 @-webkit-keyframes hide { 0% { opacity: 1; } 100% { opacity: 0; } }
 .btn {
	 position: absolute;
	 z-index: 20;
	 display: none;
	 transition: all 0.2s;
	 width: 40px;
	 height: 40px;
	 margin: -20px 0 0 -20px;
	 text-align: center;
	 line-height: 40px;
	 text-decoration: none;
	 color:black;
}
 .btn:hover {background: rgba(255, 255, 255, 0.8);}
 .btn--close { top: 40px; right: 20px; }
 .btn--close:after { content: '\2715'; }
 .btn--left { top: 50%; left: 40px; }
 .btn--left:after { content: '⯇'; }
 .btn--right { top: 50%; right: 20px; }
 .btn--right:after { content: '⯈'; }
    <span class="feature_category active" id="A">
    						 <div class="feature_box_wrapper"><a href="#groys1">Link</a></div>
    						 <br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line
                  			  <div class="feature_box_wrapper"><a href="#groys2">Link</a></div>
    						  <br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line
    						  <div class="feature_box_wrapper"><a href="#groys3">Link</a></div>
    						  <br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line
                  			 
    					</span>
    
      
     
    <div class="lightbox">
    	<!-- Groys -->
    	<div class="lightbox__slide" id="groys1">
    		<a href="#_" class="btn btn--close"></a>
    		<a href="#groys5" class="btn btn--left"></a>
    		<a href="#groys2" class="btn btn--right"></a>
    		<img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
    	</div>
    	<div class="lightbox__slide" id="groys2">
        <a href="#_" class="btn btn--close"></a>
        <a href="#groys1" class="btn btn--left"></a>
        <a href="#groys3" class="btn btn--right"></a>
        <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
      </div>
      <div class="lightbox__slide" id="groys3">
        <a href="#_" class="btn btn--close"></a>
        <a href="#groys2" class="btn btn--left"></a>
        <a href="#groys4" class="btn btn--right"></a>
        <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
      </div>      
    
      <div class="lightbox__bg"></div><!-- Close -->
    </div><!-- Close Lightbox -->

  

这里是fiddle

css carousel lightbox
1个回答
0
投票

请尝试一下...我们在此处添加固定的灯箱

html

<span class="feature_category active" id="A">
                         <div class="feature_box_wrapper"><a href="#groys1">Link</a></div>
                         <br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line
                          <div class="feature_box_wrapper"><a href="#groys2">Link</a></div>
                          <br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line
                          <div class="feature_box_wrapper"><a href="#groys3">Link</a></div>
                          <br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line
                          <div class="feature_box_wrapper"><a href="#groys4">Link</a></div>
                          <br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line
                          <div class="feature_box_wrapper"><a href="#groys5">Link</a></div>
                          <br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line<br>Line
                    </span>



<div class="lightbox">
    <!-- Groys -->
    <div class="lightbox__slide" id="groys1">
        <a href="#_" class="btn btn--close"></a>
        <a href="#groys5" class="btn btn--left"></a>
        <a href="#groys2" class="btn btn--right"></a>
        <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
    </div>
    <div class="lightbox__slide" id="groys2">
    <a href="#_" class="btn btn--close"></a>
    <a href="#groys1" class="btn btn--left"></a>
    <a href="#groys3" class="btn btn--right"></a>
    <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
  </div>
  <div class="lightbox__slide" id="groys3">
    <a href="#_" class="btn btn--close"></a>
    <a href="#groys2" class="btn btn--left"></a>
    <a href="#groys4" class="btn btn--right"></a>
    <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
  </div>
  <div class="lightbox__slide" id="groys4">
    <a href="#_" class="btn btn--close"></a>
    <a href="#groys3" class="btn btn--left"></a>
    <a href="#groys5" class="btn btn--right"></a>
    <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
  </div>
  <div class="lightbox__slide" id="groys5">
    <a href="#_" class="btn btn--close"></a>
    <a href="#groys4" class="btn btn--left"></a>
    <a href="#groys1" class="btn btn--right"></a>
    <img src="https://picsum.photos/seed/picsum/800/450" alt="Screenshot of your site">
  </div>


  <div class="lightbox__bg"></div><!-- Close -->
</div><!-- Close Lightbox -->

css

.feature_category{
  position:relative;
  z-index:999;
}
.lightbox{
  position:fixed;
  top:0;
  right:0;
  width:100%;
  height:100%;
}
.lightbox__slide img {
     position: absolute;
     z-index: 30;
     max-width: 90%;
     max-height: 80%;
     top: 50%;
     left: 50%;
     transform: translate(-50%, -50%);
     animation-name: hide;
     animation-duration: 0.5s;
     animation-iteration-count: 1;
     animation-direction: linear;
     animation-fill-mode: forwards;
}
 .lightbox__slide:target .btn { display: block; }
 .lightbox__slide:target img {
     opacity: 0;
     animation-name: show;
     animation-duration: 0.5s;
     animation-iteration-count: 1;
     animation-direction: linear;
     animation-fill-mode: forwards;
}
 .lightbox__slide:target ~ .lightbox__bg {
     position: relative;
     background:white;
     opacity: 0.6;
     top: 0;
     left: 0;
     width: 100%;
     height: 100%;
     z-index: 1;
}

 @-webkit-keyframes show { 0% { opacity: 0; } 100% { opacity: 1; } }
 @-webkit-keyframes hide { 0% { opacity: 1; } 100% { opacity: 0; } }
 .btn {
     position: absolute;
     z-index: 20;
     display: none;
     transition: all 0.2s;
     width: 40px;
     height: 40px;
     margin: -20px 0 0 -20px;
     text-align: center;
     line-height: 40px;
     text-decoration: none;
     color:black;
}
 .btn:hover {background: rgba(255, 255, 255, 0.8);}
 .btn--close { top: 40px; right: 20px; }
 .btn--close:after { content: '\2715'; }
 .btn--left { top: 50%; left: 40px; }
 .btn--left:after { content: '⯇'; }
 .btn--right { top: 50%; right: 20px; }
 .btn--right:after { content: '⯈'; }
© www.soinside.com 2019 - 2024. All rights reserved.