<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
.container {
display: flex;
min-height: 100vh;
overflow: hidden;
}
.sidebar {
flex: 0 0 200px;
background-color: #333;
color: white;
padding: 20px;
}
.content {
flex: 1;
padding: 20px;
}
header {
background-color: #4CAF50;
color: white;
padding: 10px;
text-align: center;
}
.custom-control {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.toggle-button {
background-color: #4CAF50;
color: white;
padding: 10px;
border: none;
cursor: pointer;
}
.hidden {
display: none;
}
</style>
<title>Flex 自定义控件</title>
</head>
<body>
<div class="container">
<div class="sidebar">
<h2>Sidebar</h2>
<p>Some content in the sidebar.</p>
</div>
<div class="content">
<header>
<h1>Flex 自定义控件</h1>
</header>
<div class="custom-control">
<span>Toggle Content:</span>
<button class="toggle-button" onclick="toggleContent()">Toggle</button>
</div>
<div class="content-area hidden">
<p>This is the hidden content area.</p>
</div>
</div>
</div>
<script>
function toggleContent() {
const contentArea = document.querySelector('.content-area');
contentArea.classList.toggle('hidden');
}
</script>
</body>
</html>
在这个例子中,我创建了一个包含一个按钮和一个内容区的自定义控件。点击按钮时,通过 JavaScript 中的 toggleContent 函数,切换内容区的显示和隐藏状态。通过在样式表中定义了一个 .hidden 类,来控制内容区的显示状态。
这只是一个简单的例子,你可以根据实际需求创建更复杂的自定义控件,并添加更多的交互和样式。
转载请注明出处:http://www.zyzy.cn/article/detail/10784/Flex