CSS绘制标签导航栏

html:

  • 内容1
  • 内容2
  • 内容3
  • 内容4

  

css(scss):

.tab-navbar {
	display: flex;
	overflow: hidden;
	flex-direction: column-reverse;
	border-radius: 10px;
	width: 300px;
	height: 400px;
	input {
		&:nth-child(1):checked {
			& ~ nav label:nth-child(1) {
				@extend .active;
			}
			& ~ main ul {
				background-color: #f66;
				transform: translate3d(0, 0, 0);
			}
		}
		&:nth-child(2):checked {
			& ~ nav label:nth-child(2) {
				@extend .active;
			}
			& ~ main ul {
				background-color: #66f;
				transform: translate3d(-25%, 0, 0);
			}
		}
		&:nth-child(3):checked {
			& ~ nav label:nth-child(3) {
				@extend .active;
			}
			& ~ main ul {
				background-color: #f90;
				transform: translate3d(-50%, 0, 0);
			}
		}
		&:nth-child(4):checked {
			& ~ nav label:nth-child(4) {
				@extend .active;
			}
			& ~ main ul {
				background-color: #09f;
				transform: translate3d(-75%, 0, 0);
			}
		}
	}
	nav {
		display: flex;
		height: 40px;
		background-color: #f0f0f0;
		line-height: 40px;
		text-align: center;
		label {
			flex: 1;
			cursor: pointer;
			transition: all 300ms;
		}
	}
	main {
		flex: 1;
		ul {
			display: flex;
			flex-wrap: nowrap;
			width: 400%;
			height: 100%;
			transition: all 300ms;
		}
		li {
			display: flex;
			justify-content: center;
			align-items: center;
			flex: 1;
			font-weight: bold;
			font-size: 20px;
			color: #fff;
		}
	}
}
.active {
	background-color: #3c9;
	color: #fff;
}

  

你可能感兴趣的:(CSS绘制标签导航栏)