css使用details标签实现tab选项卡切换代码

代码语言:html

所属分类:选项卡

代码描述:css使用details标签实现tab选项卡切换代码,无js代码,details标签结合css实现。

代码标签: css details 标签 实现 tab 选项卡 切换 代码

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

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  
 <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Libre+Franklin:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
  
<style>
body {
  font-family: "Libre Franklin", Arial, sans-serif;
  max-width: 50rem;
  margin: 4rem auto;
  background: #16262c;
  color: #ddd;
  padding: max(calc(50vh - 22rem), 1rem) 1rem 1rem;
  font-size: 18px;
}

h1 {
  margin-bottom: 2em;
  text-align: center;
  color: #fff;
}
h1 span {
  color: #77b728;
}

p {
  color: #ffffff7f;
  font-size: 1.2rem;
  line-height: 1.66;
  font-weight: 300;
  margin: 1rem 0 1.5rem;
}
p strong {
  color: #ddd;
  font-weight: 700;
}

.details-tab {
  padding: 0.5rem 1rem;
  font-size: 1.1rem;
  color: #ffffffcc;
  font-weight: 600;
  display: block;
  order: 0;
  background: #ffffff13;
  border-radius: 1.5rem;
  margin-right: 0.35rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  border: 2px solid transparent;
}
.details-tab:hover, .details-tab:focus {
  border-color: #fff;
}
.details-tab::-webkit-details-marker {
  display: none;
}

.details-tabs {
  position: relative;
  justify-content: center;
  display: flex;
  flex-wrap: wrap;
}

.details-content {
  order: 1;
  padding: 1rem;
  width: 100%;
}
.details-content details {
  margin: 1.5rem;
}
.details-content details summary {
  font-weight: 600;
}

.details-item {
  display: contents;
}
.details-item[open] > .details-tab {
  background: #fff;
  color: #333;
}
</style>

  
</head>

<body translate="no">
 
<h1>Using the <span>&lt;details&gt;</span> tag to create tabs</h1>
<div class="details-tabs">
	<details class="details-item" open name="test"> <!-- default first "tab" to open -->
		<summary class="details-tab">The details tag</summary>
		<div class="details-content">
			<p>Imagine an <strong>accordion-like element</strong> with <strong>native keyboard support</strong> that doesn't require javascript for control.</p>
			<p>Enter the details tag.</p>
			<details>
				<summary>The details tag</summary>
				<p>This is a details tag with content</p>
			</details>
			<p>The details tag gives us a simple accordion with no scripts&mdash;that's great! But it feels like it could be something more...imagine if it could do tabs.</p>
		</div>
	</details>
	<details class="details-item" name="test">
		<summary class="details-tab">What about tabs?</summary>
		<div class="details-content&q.........完整代码请登录后点击上方下载按钮下载查看

网友评论0