css实现玻璃质感胶囊开关效果代码

代码语言:html

所属分类:表单美化

代码描述:css实现玻璃质感胶囊开关效果代码

代码标签: css 玻璃 质感 胶囊 开关

下面为部分代码预览,完整代码请点击下载或在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">
  
  
  
<style>
* {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
:root {
	--hue: 223;
	--bg: hsl(var(--hue),10%,90%);
	--fg: hsl(var(--hue),10%,10%);
	--primary: hsl(var(--hue),90%,55%);
	--primary0: hsla(var(--hue),90%,55%,0);
	--switch-hue: 93;
	--switch: hsl(var(--switch-hue),90%,55%);
	--switch0: hsla(var(--switch-hue),90%,55%,0);
	--switch-darker: hsl(var(--switch-hue),90%,30%);
	--switch-mid-sat: hsl(var(--switch-hue),50%,55%);
	--switch-mid-sat0: hsla(var(--switch-hue),50%,55%,0);
	--switch-mid-sat3: hsla(var(--switch-hue),50%,55%,0.3);
	--trans-dur1: 0.3s;
	--trans-dur2: 0.15s;
	--trans-timing1: cubic-bezier(0.42,0,0.58,1);
	--trans-timing2: cubic-bezier(0.42,0,0.58,1.25);
	font-size: calc(48px + (60 - 48) * (100vw - 320px) / (1280 - 320));
}
body,
input {
	font: 1em/1.5 sans-serif;
}
body {
	background-color: var(--bg);
	color: var(--fg);
	height: 100vh;
	display: grid;
	place-items: center;
	align-content: center;
	transition:
		background-color var(--trans-dur1),
		color var(--trans-dur1);
}
.switch,
.switch__input {
	position: relative;
	-webkit-tap-highlight-color: transparent;
}
.switch:before,
.switch__input {
	border-radius: inherit;
	inset: 0;
}
.switch:before,
.switch__input,
.switch__input:before,
.switch__input:after,
.switch__sr,
.switch__focus {
	position: absolute;
}
.switch:before,
.switch__input:before,
.switch__input:after,
.switch__focus {
	display: block;
}
.switch:before,
.switch__input:before,
.switch__input:after {
	content: "";
}
.switch {
	border-radius: 0.75em;
	box-shadow: 0 0.3em 0.5em hsla(0,0%,0%,0.2);
	margin-bottom: 0.5em;
	width: 3em;
	height: 1.5em;
}
.switch:before {
	background-image: linear-gradient(-10deg,hsla(0,0%,100%,0) 49%,hsla(0,0%,100%,0.1) 50%);
	box-shadow:
		0 0 0 0.1em hsla(0,0%,95%) inset,
		0 0.1em 0 hsl(var(--hue),20%,85%),
		0.2em 0.25em 0.05em hsla(var(--switch-hue),10%,10%,0.08) inset;
	transition: box-shadow var(--trans-dur1);
	z-index: 2;
}
.switch__input {
	background:
		radial-gradient(circle at 50% 67%,var(--switch),var(--switch-mid-sat0) 50%),
		radial-gradient(100% 100% at 100% 100%,var(--switch),var(--switch-mid-sat0) 50%),
		var(--switch-darker);
	box-shadow:
		-0.125em 0 0.25em hsla(0,0%,0%,0.3) inset,
		-0.125em 0.125em 0.375em 0.25em var(--switch-mid-sat) inset,
		0 0.3em 0.25em v.........完整代码请登录后点击上方下载按钮下载查看

网友评论0