CSS综合案例4

CSS综合案例4

1. 综合案例

我们来做一个静态的轮播图。

2. 分析思路

  1. 首先需要加载一张背景图进去
  2. 需要4个小圆点,设置样式,并用定位和平移调整位置
  3. 添加两个箭头,也是需要用定位和位移进行调整位置

3. 代码演示

html文件

html 复制代码
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>静态轮播图</title>
		<link rel="stylesheet" href="./style.css" />
	</head>
	<body>
		<div class="box">
			<img src="./R-C.jpg" alt="穿越火线" />
			<div class="arrow1">
				<p><</p>
			</div>
			<div class="arrow2">
				<p>></p>
			</div>
			<div class="Carousel"></div>
			<div class="wrapper">
				<div class="point"></div>
				<div class="point"></div>
				<div class="point"></div>
				<div class="point"></div>
			</div>
		</div>
	</body>
</html>

css文件

css 复制代码
* {
	box-sizing: border-box;
}
.box {
	width: 1024px;
	height: 729px;
	position: absolute;
	left: 50%;
	top: 50%;
	/*translateX x轴位移,单位百分比或者px */
	transform: translate(-50%, -50%);
}

.arrow1 {
	width: 30px;
	height: 40px;
	background-color: #3e3f43;
	border-radius: 0 70% 60% 0;
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	opacity: 0.5;
	cursor: pointer;
}
.arrow2 {
	width: 30px;
	height: 40px;
	background-color: #3e3f43;
	border-radius: 70% 0 0 60%;
	position: absolute;
	top: 50%;
	left: 994px;
	transform: translateY(-50%);
	opacity: 0.5;
	cursor: pointer;
}

.arrow1 > p {
	position: absolute;
	left: 6px;
	top: -13px;
	font-size: 20px;
	color: #fff;
}
.arrow2 > p {
	position: absolute;
	left: 9px;
	top: -13px;
	font-size: 20px;
	color: #fff;
}
.Carousel {
	position: absolute;
	left: 50%;
	bottom: 20px;
	transform: translateX(-50%);
	width: 120px;
	height: 20px;
	border: 1px solid #ccc;
	background-color: #fff;
	border-radius: 20px;
	display: flex;
	align-items: center;
	justify-content: space-around;
	opacity: 0.1;
}

.point {
	left: 50%;
	bottom: 20px;
	transform: translateX(-50%);
	width: 10px;
	height: 10px;
	background-color: #fafafa;
	border-radius: 50%;
	cursor: pointer;
}
.wrapper {
	position: absolute;
	left: 50%;
	bottom: 20px;
	transform: translateX(-50%);
	width: 120px;
	height: 20px;
	border-radius: 20px;
	display: flex;
	align-items: center;
	justify-content: space-around;
}

.point:hover {
	background-color: #f55719;
}
相关推荐
Lank_M1 小时前
白底都占八成,PNG 为何只在图表页赢过 JPG
前端
张一凡931 小时前
给 Coding Agent 加一道"架构闸门":Jin 是如何做到"先审架构、再写代码、不漂移"的
前端·后端·agent
Linye1 小时前
AI 写的 HTML 原型全是空壳?聊聊真实 DOM 交互避坑
前端·人工智能
ZANE1 小时前
纯前端实现的 PDF 与图片互相转换工具技术实现
前端
Swot2 小时前
SvelteKit Remote Functions 使用指南
前端·后端
Cooper252 小时前
三源热榜去重加 AI 摘要:URL 唯一键踩出的三个坑
前端·python
Yk酱228402 小时前
A2UI探索随笔-技术选型
前端
前端繁华如梦2 小时前
# 从 73000 行压缩代码到 TypeScript 模块化:我把一个 Three.js FPS 游戏 1:1 复刻了一遍
前端
Penge6662 小时前
React Context 详解:从 Props 传递到跨组件状态共享
前端
Penge6662 小时前
React 事件处理:bind(this) 原理与实际开发常用写法
前端