【Web】CSS(No.26)定位经典案例(一)《静态轮播图》


需要素材点击图片联系我或私信、评论

效果图:

在这里插入图片描述

源码:
<!DOCTYPE html>
<html lang="en">
  <head>
	<meta charset="UTF-8">
	<title>静态轮播图</title>
	<style>
	  * {
	  	margin:0;
	  	padding:0;
	  }

	  .banner {
	  	width: 520px;
	  	height: 280px;
	  	margin: 100px auto;
	  	position: relative;
	  }

	  .banner .img img {
	  	position: absolute;
	  	top:0;
	  	left:0;
	  }

	  .banner ul {
	  	width: 80px;
	  	height: 15px;
	  	position: absolute;
	  	left: 50%;
	  	margin-left: -40px;
	  	bottom: 20px;
	  	background-color: rgba(255,255,255,0.2);
	  	border-radius: 10px;
	  }

	  .banner ul li {
	  	float:left;
	  	list-style: none;
	  	width: 8px;
	  	height: 8px;
	  	border-radius: 50px;
	  	background-color: #dddddd;
	  	margin: 2px;
	  	margin:3px 4px;
	  }

	  .banner ul li:hover {
	  	background-color: darkred;
	  }

	   .banner ul li.now {
	   	background-color: darkred;
	   }

	  .banner a {
	  	color:#dddddd;
	  	text-decoration: none;
	  	position: absolute;
	  	top: 50%;
	  	margin-top:-20px;
	  	width: 30px;
	  	height: 40px;
	  	text-align: center;
	  	line-height: 40px;
	  	font-size:20px;
	  }

	  .banner a:hover {
	  	color: darkred;
	  }

	  .banner a.left {
	  	width: 45px;
	  	height: 45px;
	  	border-radius: 50px;
	  	background-color:  rgba(255,255,255,0.2);
	  	left:0;
	  }

	   .banner a.right {
	   	width: 45px;
	  	height: 45px;
	  	border-radius: 50px;
	  	background-color:  rgba(255,255,255,0.2);
	  	right:0;
	  }
	</style>
  </head>
  <body>
	<div class="banner">
	  <!-- 图片容器 -->
	  <div class="img">
	    <img src="img/tb.jpg" alt="">
	    <img src="img/taobao.jpg" alt="">
	    <img src="img/tb.jpg" alt="">
	    <img src="img/taobao.jpg" alt="">
	    <img src="img/tb.jpg" alt="">
	  </div>

	  <!-- 点容器 -->
	  <ul>
	    <li class="now"></li>
	    <li></li>
	    <li></li>
	    <li></li>
	    <li></li>
	  </ul>

	  <!-- 按钮 -->
	  <a class="left" href="#">&lt;&lt;</a>
	  <a class="right" href="#">&gt;&gt;</a>
	</div>
  </body>
</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的静态轮播图的HTML代码: ```html <!DOCTYPE html> <html> <head> <title>静态轮播图</title> <style> .container { width: 500px; height: 300px; overflow: hidden; position: relative; } .slide { position: absolute; top: 0; left: 0; width: 500px; height: 300px; opacity: 0; transition: opacity 1s ease-in-out; } .slide.active { opacity: 1; transition: opacity 1s ease-in-out; } .slide:first-child { opacity: 1; } .nav { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); display: flex; } .nav button { width: 10px; height: 10px; border-radius: 50%; margin: 0 5px; background-color: #ccc; border: none; cursor: pointer; } .nav button.active { background-color: #333; } </style> </head> <body> <div class="container"> <div class="slide active"> <img src="slide1.jpg" alt="Slide 1"> </div> <div class="slide"> <img src="slide2.jpg" alt="Slide 2"> </div> <div class="slide"> <img src="slide3.jpg" alt="Slide 3"> </div> <div class="slide"> <img src="slide4.jpg" alt="Slide 4"> </div> <div class="nav"> <button class="active"></button> <button></button> <button></button> <button></button> </div> </div> <script> let slides = document.querySelectorAll('.slide'); let buttons = document.querySelectorAll('.nav button'); let currentSlide = 0; function nextSlide() { slides[currentSlide].classList.remove('active'); buttons[currentSlide].classList.remove('active'); currentSlide = (currentSlide + 1) % slides.length; slides[currentSlide].classList.add('active'); buttons[currentSlide].classList.add('active'); } let slideInterval = setInterval(nextSlide, 5000); </script> </body> </html> ``` 这个代码中包含一个容器 `.container` 和多个轮播项 `.slide`,以及一个导航栏 `.nav`。轮播项使用 CSS 的 `position: absolute` 属性定位,导航栏使用 flexbox 布局,并且通过 JavaScript 实现轮播的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值