<!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; /* 不可伸缩,初始宽度为200px */
background-color: #333;
color: white;
padding: 20px;
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
}
.content {
flex: 1; /* 可伸缩,占据剩余空间 */
padding: 20px;
}
header {
background-color: #4CAF50;
color: white;
padding: 10px;
text-align: center;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
.card {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
padding: 20px;
margin-bottom: 20px;
}
</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="card">
<h2>Card Title 1</h2>
<p>This is some content inside the card.</p>
</div>
<div class="card">
<h2>Card Title 2</h2>
<p>Another card with different content.</p>
</div>
</div>
</div>
</body>
</html>
在这个示例中,我添加了一些视觉效果:
1. .container 设置了 overflow: hidden;,以防止内容溢出。
2. .sidebar 和 header 分别应用了 box-shadow,为它们添加了阴影效果。
3. .card 类表示一个卡片,它应用了圆角、阴影和内边距,使其看起来更像一个卡片。
这些效果可以根据实际需求进行调整,使页面更加吸引人。
转载请注明出处:http://www.zyzy.cn/article/detail/10782/Flex