輪播圖是一種常見的網頁交互元素,常用于展示多個圖片或視頻的輪流顯示。使用 CSS 樣式可以輕松創建輪播圖,以下是一個簡單的示例:
HTML 代碼:
<div class="slideshow">
</div>
CSS 樣式:
.slideshow {
position: relative;
width: 300px;
height: 200px;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
.slideshow:before,
.slideshow:after {
content: "";
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
border-top: 200px solid black;
.slideshow:after {
left: 50%;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 200px solid black;
.slideshow:before {
right: 50%;
width: 0;
height: 0;
border-right: 50px solid transparent;
border-left: 50px solid transparent;
border-top: 200px solid black;
.active {
display: none;
.active:before,
.active:after {
content: "";
position: absolute;
top: 0;
left: 50%;
width: 0;
height: 0;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
border-bottom: 200px solid black;
.active:after {
left: 50%;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 200px solid black;
@media screen and (max-width: 768px) {
width: 16px;
height: 16px;
.active {
display: block;
通過使用上述 CSS 樣式,我們可以創建一個簡單的輪播圖,該輪播圖包含三張圖片輪流顯示。只需簡單地將此代碼復制粘貼到您的網頁中,即可使用 CSS 樣式創建您自己的輪播圖。