案例

人物留言

代码

translate 实现绝对定位时的居中位置

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link rel="preconnect" href="https://fonts.gstatic.com" />
		<link
			href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
			rel="stylesheet"
		/>
		<title>Carousel component</title>
		<style type="text/css">
			/*
			         SPACING SYSTEM (px)
			         2 / 4 / 8 / 12 / 16 / 24 / 32 / 48 / 64 / 80 / 96 / 128
 
			         FONT SIZE SYSTEM (px)
			         10 / 12 / 14 / 16 / 18 / 20 / 24 / 30 / 36 / 44 / 52 / 62 / 74 / 86 / 98
			         */
 
			/*
			         主色:#087f5b
			         字体:#343a40
			         */
 
			* {
				margin: 0;
				padding: 0;
				box-sizing: border-box;
			}
			body {
				font-family: "Inter", "Microsoft YaHei";
				color: #495057;
				line-height: 1;
			}
			.carousel {
				background-color: #087f5b;
				width: 800px;
				margin: 100px auto;
				border-radius: 8px;
 
				padding: 32px 48px 32px 86px;
 
				display: flex;
				align-items: center;
				gap: 86px;
				position: relative;
			}
 
			img {
				height: 200px;
				border-radius: 8px;
				transform: scale(1.5);
				box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
			}
 
			.testimonial {
			}
 
			.testimonial-text {
				color: #e6fcf5;
				font-size: 18px;
				font-weight: 500;
				line-height: 1.5;
				margin-bottom: 32px;
			}
			.testimonial-author {
				color: #c3fae8;
				font-size: 14px;
				margin-bottom: 4px;
			}
			.testimonial-job {
				font-size: 12px;
				color: #c3fae8;
			}
 
			/* CONTROLS */
			.btn {
				width: 40px;
				height: 40px;
				border: none;
				position: absolute;
 
				border-radius: 50%;
 
				display: flex;
				justify-content: center;
				align-items: center;
 
				box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
 
				cursor: pointer;
			}
 
			.btn--left {
				left: 0;
				top: 50%;
				transform: translate(-50%, -50%);
			}
 
			.btn--right {
				right: 0;
				top: 50%;
				transform: translate(50%, -50%);
			}
 
			.btn-icon {
				stroke: #087f5b;
				width: 24px;
				height: 24px;
			}
 
			.dots {
				position: absolute;
				bottom: 0;
				left: 50%;
				transform: translate(-50%, 32px);
				display: flex;
				gap: 12px;
			}
 
			.dot {
				height: 12px;
				width: 12px;
				background-color: #fff;
				border-radius: 50%;
				border: 2px solid #087f5b;
				cursor: pointer;
			}
 
			.dot--fill {
				background-color: #087f5b;
			}
		</style>
	</head>
	<body>
		<div class="carousel">
			<img src="maria.jpg" />
			<blockquote class="testimonial">
				<p class="testimonial-text">
					Lorem ipsum dolor sit amet consectetur adipisicing elit.
					Praesentium distinctio placeat rerum incidunt sit, dolor
					iure optio quaerat qui!
				</p>
				<p class="testimonial-author">Maria de Alemeida</p>
				<p class="testimonial-job">
					Senior Product Manager at EDP Comercial
				</p>
			</blockquote>
			<button class="btn btn--left">
				<svg
					xmlns="http://www.w3.org/2000/svg"
					fill="none"
					viewBox="0 0 24 24"
					stroke-width="1.5"
					stroke="currentColor"
					class="btn-icon"
				>
					<path
						stroke-linecap="round"
						stroke-linejoin="round"
						d="M15.75 19.5L8.25 12l7.5-7.5"
					/>
				</svg>
			</button>
			<button class="btn btn--right">
				<svg
					xmlns="http://www.w3.org/2000/svg"
					fill="none"
					viewBox="0 0 24 24"
					stroke-width="1.5"
					stroke="currentColor"
					class="btn-icon"
				>
					<path
						stroke-linecap="round"
						stroke-linejoin="round"
						d="M8.25 4.5l7.5 7.5-7.5 7.5"
					/>
				</svg>
			</button>
			<div class="dots">
				<button class="dot dot--fill">&nbsp;</button>
				<button class="dot">&nbsp;</button>
				<button class="dot">&nbsp;</button>
				<button class="dot">&nbsp;</button>
			</div>
		</div>
	</body>
</html>