Beispiel:Scroll-Snap-3.html

Aus SELFHTML-Wiki
Wechseln zu: Navigation, Suche

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Bilder-Karussell </title> <style> .carousel {

--carousel-width: clamp(0px, 100vw, 60em);
 width: var(--carousel-width);
 aspect-ratio: 5 / 3;
 display: flex;
 overflow-x: auto;       
 scroll-snap-type: x mandatory; 
 scroll-behavior: smooth;
 & li {
 flex: 0 0 100%;           
 scroll-snap-align: start;
   
 }

}

@supports selector(::scroll-marker) {

 .carousel {
   overflow: hidden;             /* Bei Support können alle Bilder übereinander gestapelt werden */
   anchor-name: --carousel;
   scroll-marker-group: after;
 &::scroll-button(*) {
   position-anchor: --carousel;
   position: fixed;
   align-self: anchor-center;

width: 1.5em; background: white;

   border-radius: 1em;
   border: thin solid skyblue;		
 }
 &::scroll-button(*):hover {

background: skyblue; }

 &::scroll-button(left) {
   content: "⬅︎";
   left: calc(anchor(left) + 1em);
 }
 &::scroll-button(right) {
   content: "⮕";
   right: calc(anchor(right) + 1em);
 }		


 &::scroll-marker-group {
   display: flex;
   gap: 1em;
   position: fixed;
   position-anchor: --carousel;
   justify-self: anchor-center;
   bottom: calc(anchor(bottom) + 1em);
   
 }
 li::scroll-marker {
   /* Stylized markers */
   content: "";
   width: 1em;
   aspect-ratio: 1;
   background: white;
   border-radius: 1em;
   border: thin solid skyblue;
 }
 li::scroll-marker:target-current {
   background: skyblue;
 }

} }



img { display: block;

 width: 100%;
 height: 100%;
 object-fit: cover; 

}


.carousel {

 margin: 0;
 padding: 0;
 list-style: none;

}

  1. browsersupport span::before {
 @supports selector(::scroll-marker) {
   content: "unterstützt";
   background: rgb(0 255 0 / 30%);
 }
 @supports not selector(::scroll-marker) {
   content: "Nicht unterstützt";
   background: rgb(255 0 0 / 30%);
 }

}

h1 span { display: block;

 margin-inline-start: 7em;

} </style>


</head>

<body>

Bilder-Karussell mit scroll-button()
und scroll-marker-group

<a href="https://caniuse.com/mdn-css_selectors_scroll-marker" target="_blank">Browser Support</a>:

</body> </html>