svg+css实现一款拟态手机运动类app界面UI效果代码

代码语言:html

所属分类:布局界面

代码描述:svg+css实现一款拟态手机运动类app界面UI效果代码

代码标签: svg css 拟态 运动 app ui

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"><link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;700&amp;display=swap'>
  
  <style>
      * {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
:root {
	--hue: 184;
	--bg: hsl(var(--hue),10%,90%);
	--fg: hsl(var(--hue),66%,24%);
	--primary: hsl(var(--hue),66%,44%);
	--gradient: linear-gradient(145deg, hsl(var(--hue),10%,85%), hsl(var(--hue),10%,100%));
	font-size: 16px;
}
body,
button {
	color: var(--fg);
	font: 1em/1.5 "Nunito", sans-serif;
}
body {
	background: var(--bg);
	height: 100vh;
	display: grid;
	place-items: center;
	padding: 1.5em 0 0 0;
}
body:after {
	content: "";
	display: block;
	height: 1.5em;
	width: 100%;
}
/* All */
.app,
.header,
.main__date-nav,
.main__stat-row,
.main__stat-graph,
.footer {
	display: flex;
}
.header,
.main__date-nav,
.footer {
	justify-content: space-between;
}
.header__profile-btn,
.header__notes-btn,
.main__date-arrow-btn,
.main__date-edit-btn,
.footer__nav-btn {
	background: transparent;
	display: flex;
	outline: transparent;
	transition: all 0.15s linear;
	-webkit-appearance: none;
	appearance: none;
	-webkit-tap-highlight-color: transparent;
}
.app {
	background: hsl(var(--hue),10%,85%);
	border-radius: 3em;
	flex-direction: column;
	padding: 2.25em;
	width: 390px;
	height: 844px;
}
.app__gradients {
	position: absolute;
	width: 1px;
	height: 1px;
}
.icon {
	display: block;
	margin: auto;
	width: 1.5em;
	height: 1.5em;
}
.icon circle,
.icon path {
	fill: currentColor;
	transition: fill 0.15s linear;
}
.icon ellipse,
.icon polygon {
	stroke: currentColor;
	transition: stroke 0.15s linear;
}
.icon .no-fill {
	fill: none;
	stroke: currentColor;
}
.icon--red path {
	fill: hsl(3,90%,55%);
}
.icon--pulse {
	animation:
		bpm 1s linear,
		pulse 0.75s 1s linear infinite;
}
.ring,
.sr-only {
	position: absolute;
}
.ring {
	display: block;
	inset: 0;
	width: 100%;
	height: auto;
}
.ring-fill {
	 stroke: url("#ring");
}
.ring-stroke {
	animation-duration: 1s;
	animation-timing-function: ease-in-out;
	stroke: url("#ring");
}
.ring-stroke--steps {
	animation-name: stepCount;
}
.ring-stroke--cals {
	animation-name: cals;
}
.ring-stroke--miles {
	animation-name: miles;
}
.ring-stroke--mins {
	animation-name: mins;
}
.ring-stroke--stepHrs {
	animation-name: stepHrs;
}
.ring-track {
	stroke: hsl(var(--hue),10%,80%);
}
.sr-only {
	clip: rect(1px,1px,1px,1px);
	overflow: hidden;
	width: 1px;
	height: 1px;
}
/* Header */
.header {
	display: flex;
	justify-content: space-between;
	margin-bottom: 1.5em;
}
.header__profile-btn,
.header__notes-btn {
	width: 3em;
	height: 3em;
}
.header__profile-btn {
	border-radius: 1em;
	box-shadow: 0 0 0 0.125em inset;
}
.header__notes-btn {
	margin-right: -1em;
}
.header__profile-btn:active,
.header__notes-btn:active {
	transform: scale(0.9);
}
.header__profile-btn:focus {
	box-shadow: 0 0 0 0.125em var(--primary) inset;
}
.header__profile-icon {
	border-radius: 0.5em;
	margin: auto;
	width: 2em;
	height: 2em;
}
.header__notes-btn:focus .icon path {
	fill: var(--primary);
}
/* Main */
.main__date-nav {
	margin-bottom: 1.5em;
}
.main__date-arrow-btn,
.main__date-edit-btn {
	height: 1.5em;
}
.main__date-arrow-btn {
	width: 1.5em;
}
.main__date-arrow-btn:active .icon path,
.main__date-arrow-btn:focus .icon path {
	fill: var(--primary);
}
.main__date {
	text-transform: uppercase;
}
.main__date-edit-btn {
	min-width: 1.5em;
}
.main__date-edit-btn:active,
.main__date-edit-btn:focus {
	color: var(--primary);
}
.main__stat-blocks {
	display: grid;
	grid-template-columns: repeat(3,1fr);
	grid-gap: 1.5em;
	margin-bottom: 1.5em;
}
.main__stat-block {
	aspect-ratio: 1 / 1;
	background: var(--gradient);
	border-radius: 1.5em;
	box-shadow:
		-0.75em -0.75em 2.25em hsl(0,0%,100%),
		0.75em 0.75em 2.25em hsl(var(--hue),5%,65%);
	padding: 0.75em;
	text-align: center;
	width: 100%;
}
.main__stat-block--lg {
	aspect-ratio: 2 / 1;
	grid-column: 1 / 4;
	padding: 1.5em;
}
.main__stat-rows,
.main__stat-row {
	margin-bottom: 1.5em;
}
.main__stat-row {
	align-items: center;
}
.main__stat-graph {
	margin: 0 auto 0.75em auto;
	position: relative;
	width: 3.75em;
	height: 3.75em;
}
.main__stat-graph .main__stat-detail {
	display: flex;
	flex-direction: column;
	justify-content: center;
	position: absolute;
	inset: 0;
}
.main__stat-block--lg .main__stat-graph {
	margin: auto;
	width: 11.25em;
	height: 11.25em;
}
.main__stat-block--lg .icon {
	margin: 0 auto;
	width: 2.25em;
	height: 2.25em;
}
.main__stat-row .main__stat-graph {
	background: var(--gradient);
	border-radius: 1em;
	box-shadow: 
		-0.75em -0.75em 2.25em hsl(0,0%,100%),
		0.75em 0.75em 2.25em hsl(var(--hue),5%,65%);
	margin: 0 1.5em 0 0;
}
.main__stat-value,
.main__stat-unit {
	display: block;
}
.main__stat-value {
	font-size: 1.25em;
	line-height: 1.2;
}
.main__stat-block--lg .main__stat-value {
	font-size: 2em;
	line-height: 1.5;
}
.main__stat-unit,
.main__stat-subtext {
	font-weight: 300;
}
.main__stat-subtext {
	color: hsl(var(--hue),10%,30%);
}
.main__stat-graph--filled,
.main__stat-graph--filled .ring-fill {
	animation-duration: 0.3s;
	animation-delay: 1s;
	animation-fill-mode: forwards;
}
.main__stat-graph--filled {
	animation-name: statFill;
	animation-timing-function: linear;
}
.main__stat-graph--filled .ring-fill {
	animation-name: ringFill;
	animation-timing-function: ease-in;
}
/* Footer */
.footer {
	margin-top: auto;
}
.footer__nav-btn {
	background: var(--gradient);
	border-radius: 50%;
	box-shadow: 
		1em 1em 2em hsl(var(--hue),5%,65%),
		-1em -1em 2em hsl(0,0%,100%);
	width: 3em;
	height: 3em;
}
.footer__nav-btn:active {
	box-shadow: 
		0.75em 0.75em 1.5em hsl(var(--hue),5%,65%),
		-0.75em -0.75em 1.5em hsl(0,0%,100%);
	transform: scale(0.9);
}
.footer__nav-btn:focus .icon circle,
.footer__nav-btn:focus .icon path {
	fill: var(--primary);
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
	:root {
		--bg: hsl(var(--hue),10%,10%);
		--fg: hsl(var(--hue),66%,94%);
		--primary: hsl(var(--hue),66%,44%);
		--gradient: linear-gradient(145deg, hsl(var(--hue),10%,15%), hsl(var(--hue),10%,30%));
	}
	.app {
		background: hsl(var(--hue),10%,20%);
	}
	.icon--red path {
		fill: hsl(3,90%,65%);
	}
	.ring-track {
		stroke: hsl(var(--hue),10%,30%);
	}
	.main__stat-block,
	.main__stat-row .main__stat-graph {
		box-shadow:
			-0.75em -0.75em 2.25em hsl(var(--hue),10%,30%),
			0.75em 0.75em 2.25em hsl(var(--hue),5%,5%);
	}
	.main__stat-subtext {
		color: hsl(var(--hue),10%,70%);
	}
	.footer__nav-btn {
		box-shadow: 
			-1em -1em 2em hsl(var(--hue),10%,30%),
			1em 1em 2em hsl(var(--hue),5%,5%);
	}
	.footer__nav-btn:active {
		box-shadow: 
			-0.75em -0.75em 1.5em hsl(var(--hue),10%,30%),
			0.75em 0.75em 1.5em hsl(var(--hue),5%,5%);
	}
}

/* Animations */
@keyframes statFill {
	from {
		color: var(--fg);
	}
	to {
		color: hsl(var(--hue),66%,94%);
	}
}
@keyframes ringFill {
	from {
		r: 82px;
		stroke-width: 16;
	}
	to {
		r: 45px;
		stroke-width: 90;
	}
}
@keyframes stepCount {
	from {
		stroke-dashoffset: 515.22;
	}
	to {
		stroke-dashoffset: 0;
	}
}
@keyframes cals {
	from {
		stroke-dashoffset: 163.36;
	}
	to {
		stroke-dashoffset: 12.25;
	}
}
@keyframes miles {
	from {
		stroke-dashoffset: 163.36;
	}
	to {
		stroke-dashoffset: 35.39;
	}
}
@keyframes mins {
	from {
		stroke-dashoffset: 163.36;
	}
	to {
		stroke-dashoffset: 65.34;
	}
}
@keyframes bpm {
	from {
		transform: scale(0);
	}
	37.5% {
		transform: scale(1.2);
	}
	75%,
	to {
		transform: scale(1);
	}
}
@keyframes stepHrs {
	from {
		stroke-dashoffset: 131.95;
	}
	to {
		stroke-dashoffset: 52.78;
	}
}
@keyframes pulse {
	from,
	75%,
	to {
		transform: scale(1);
	}
	25% {
		transform: scale(0.9);
	}
	50% {
		transform: scale(1.2);
	}
}
  </style>

</head>
<body>

<div class="app">
	<svg class="app__gradients" hidden>
		<defs>
			<linearGradient id="ring" x1="1" y1="0" x2="0" y2="1">
				<stop offset="0%" stop-color="hsl(184,66%,54%)" />
				<stop offset="100%" stop-color="hsl(184,66%,34%)" />
			</linearGradient>
		</defs>
	</svg>
	<header class="header">
		<button class="header__profile-btn" type="button">
			<img class="header__profile-icon" alt="Profile (Mr. Trololo)" src="//repo.bfw.wiki/bfwrepo/image/60d41f5173b0d.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" width="48" height="48">
		</button>
		<button class="header__notes-btn" type="button" title="Notifications">
			<svg class="icon" viewBox="0 0 24 24" height="24" width="24" xmlns="http://www.w3.org/2000/svg">
				<path d="M3 5C3 3.89543 3.89543 3 5 3H19C20.1046 3 21 3.89543 21 5V19C21 20.1046 20.1046 21 19 21H5C3.89543 21 3 20.1046 3 19V5ZM5 14V19H19V14H16.7208L15.9487 16.3162C15.8126 16.7246 15.4304 17 15 17H9C8.56957 17 8.18743 16.7246 8.05132 16.3162L7.27924 14H5ZM19 12V5H5V12H7.27924C8.1401 12 8.90438 12.5509 9.17661 13.3675L9.72076 15H14.2792L14.8234 13.3675C15.0956 12.5509 15.8599 12 16.7208 12H19Z" />
			</svg>
		</button>
	</header>
	<main>
		<div class="main__date-nav">
			<button class="main__date-arrow-btn" type="button">
				<svg class="icon" viewBox="0 0 24 24" height="24" width="24" xmlns="http://www.w3.org/2000/svg">
					<path d="M14.7071 5.29289C15.0976 5.68342 15.0976 6.31658 14.7071 6.70711L9.41421 12L14.7071 17.2929C15.0976 17.6834 15.0976 18.3166 14.7071 18.7071C14.3166 19.0976 13.6834 19.0976 13.2929 18.7071L7.29289 12.7071C6.90237 12.3166 6.90237 11.6834 7.29289 11.2929L13.2929 5.29289C13.6834 4.90237 14.3166 4.90237 14.7071 5.29289Z" />
				</svg>
				<span class="sr-only">Previous</span>
			</button>
			<div class="main__date">
				<strong>Today</strong>
			</div>
			<button class="main__date-edit-btn" type="button">Edit</button>
		</div>
		<div class="main__stat-blocks">

			<div class="main__stat-block main__stat-block--lg">
				<div class="main__stat-graph main__stat-graph--filled">
					<svg class="ring" viewBox="0 0 180 180" height="180" width="180" xmlns="http://www.w3.org/2000/svg">
						<circle class="ring-track" cx="90" cy="90" r="82" fill="none" stroke="#7f7f7f" stroke-width="16" />
						<circle class="ring-stroke ring-stroke--steps" cx="90" cy="90" r="82" fill="none" stroke="#000" stroke-linecap="round" stroke-width="16" stroke-dasharray="515.22 515.22" stroke-dashoffset="0" transform="rotate(-90,90,90)" />
						<circle class="ring-fill" cx="90" cy="90" r="0" fill="none" transform="rotate(-90,90,90)" />
					</svg>
					<div class="main__stat-detail">
						<svg role="img" aria-label="Footprints" class="icon" viewBox="0 0 36 36" height="36" width="36" xmlns="http://www.w3.org/2000/svg">
						  <path class="no-fill" fill="none" stroke="#000" stroke-width="2" d="M 14.831 17.296 C 13.365 17.803 12 18.046 10.142 18.623 C 10.87 27.73 19.472 24.186 14.831 17.296 Z M 14.236 15.036 C 14.26 13.771 14.191 12.55 14.74 11.349 C 15.362 10.06 15.461 8.925 15.115 7.054 C 14.493 3.647 13.171 1.521 11.389 1.055 C 7.586 0.499 7.113 4.24 7.022 6.974 C 6.812 8.503 8.106 15.054 9.669 16.162 C 11.205 15.77 12.713 15.386 14.236 15.036 Z" />
						  <path class="no-fill" fill="none" stroke="#000" stroke-width="2" d="M 21.184 28.252 C 21.184 28.252 24.001 28.918 25.859 29.496 C 25.128 38.603 16.542 35.143 21.184 28.252 Z M 21.764 26.007 C 21.741 24.741 21.807 23.525 21.261 22.32 C 20.64 21.031 20.541 19.9 20.885 18.026 C 21.508 14.618 22.828 12.495 24.61 12.029 C 28.417 11.471 28.888 15.211 28.977 17.945 C 29.187 19.475 27.897 26.027 26.332 27.135 C 24.799 26.743 23.288 26.357 21.764 26.007 Z" />
						</svg&g.........完整代码请登录后点击上方下载按钮下载查看

网友评论0