<div class="container">
<!-- Sliderを包むコンテナ要素 -->
<div id="swiper" class="swiper">
<!-- スライド要素を包む要素 -->
<div class="swiper-wrapper">
<!-- 各スライド -->
<div class="swiper-slide slide1">
<p>スライド:1枚目</p>
</div>
<div class="swiper-slide slide2">
<p>スライド:2枚目</p>
</div>
<div class="swiper-slide slide3">
<p>スライド:3枚目</p>
</div>
</div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
<div class="swiper-pagination"></div>
</div>
.container {
margin-left: auto;
margin-right: auto;
max-width: 100%;
position: relative;
}
.swiper {
/*スライダーの幅と高さを調整*/
width: 90%;
height: 200px;
margin: 0.5rem auto;
}
.swiper-slide {
/*スライド要素の幅と高さを調整*/
width: 100%;
height: 100%;
/*テキストの位置調整*/
display: flex;
justify-content: center;
align-items: center;
/*テキストの色と太さを指定*/
color: #fff;
font-weight: bold;
}
/*各スライドの背景色の設定*/
.slide1 {
background-color: #88acbd;
}
.slide2 {
background-color: #99cb1f;
}
.slide3 {
background-color: #e43a47;
}
/* ページネーション */
.swiper-pagination-bullets.swiper-pagination-horizontal,
.swiper-pagination-custom,
.swiper-pagination-fraction {
bottom: -3rem; //3文字分下に下げる
}
/* ドット */
.swiper-pagination-horizontal.swiper-pagination-bullets
.swiper-pagination-bullet {
width: 1.5rem;
height: 1.5rem;
margin: 0.4rem;
background: #88abda;
color: #fff;
font-weight: bold;
cursor: pointer;
opacity: 1;
}
/*アクティブなときのスタイル*/
.swiper-pagination-horizontal.swiper-pagination-bullets
.swiper-pagination-bullet.swiper-pagination-bullet-active {
transform: scale(1.4);
border-radius: 50%;
background-image: radial-gradient(
#88abda 0% 40%,
#fff 40% 50%,
#88abda 50% 100%
);
}
const swiper = new Swiper(".swiper", {
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev"
},
pagination: {
el: ".swiper-pagination", //必須の設定:ページネーションのclass指定
type: "bullets",
clickable: "clickable"
}
});