<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>纯CSS实现轮播图(自动轮播)</title>
	<link rel="stylesheet" href="../css/reset.css">
	<link rel="stylesheet" href="../css/autoMatic.css">
</head>

<body>
	<!-- 创建外部展示容器 -->
	<div class="banner-container">
		<!-- 创建图片存储容器 -->
		<div class="banner-img-container">
			<img src="../img/banner01.png" alt="">
			<img src="../img/banner02.png" alt="">
			<img src="../img/banner03.png" alt="">
			<img src="../img/banner04.png" alt="">
			<img src="../img/banner05.png" alt="">
		</div>
	</div>
</body>

</html>

autoMatic.css

@charset "utf-8";
/* CSS Document */

/* 自动轮播样式 */
.banner-container{
	width:1200px;
	height:400px;
	/* 轮播图居中 */
	margin:1rem auto;
	/* 隐藏超出展示容器内容 */
	overflow: hidden;
	position: relative;
}

.banner-container .banner-img-container {
	width:6000px;
	height:400px;
	overflow: hidden;
	position: absolute;
	/* 开启弹性盒,让图片横向排列 */
	display: flex;
	animation: run 10s ease infinite;
}

.banner-container .banner-img-container img{
	width:1200px;
	height:100%;
}

/* 动画关键帧 */
@keyframes run {
	0%,10%{
		/* margin-left: 0; */
		transform: translateX(0);
	}
	20%,30%{
		/* margin-left: -1200px;; */
		transform: translateX(-1200px);
	}
	40%,50%{
		/* margin-left: -2400px; */
		transform: translateX(-2400px);
	}
	60%,70%{
		/* margin-left: -3600px; */
		transform: translateX(-3600px);
	}
	80%,90%{
		/* margin-left: -4800px; */
		transform: translateX(-4800px);
	}
	100%{
		/* margin-left: 0; */
		transform: translateX(0);
	}
}

reset.css

@charset "utf-8";
/* CSS Document */

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}

img

原文地址:https://blog.csdn.net/weixin_70349146/article/details/133086229

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_17245.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注