使用 HTML 和 CSS 创建带侧栏和主要内容区域的页面
通过将 html 和 body 的大小设置为 100%,可以创建一个具有流动侧栏和主要内容区域的网页。
以下示例对此进行了说明。
示例
<!DOCTYPE html>
<html>
<head>
<style>
html,body {
height: 100%;
color: white;
font-size: 2em;
line-height: 200px;
}
#parent {
display: table;
width: 100%;
height: 100%;
}
#side {
display: table-cell;
background-color: turquoise;
width: 20%;
vertical-align: top;
box-shadow: inset 0 0 10px black;
}
#main {
display: table-cell;
width: 80%;
background: url("https://images.unsplash.com/photo-1611944444060- b50a1d80cfe6?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=800&ixlib=rb1.2.1&q=80&w=600");
}
</style>
</head>
<body>
<div id="parent">
<div id="side">Side</div>
<div id="main">Main</div>
</div>
</body>
</html>输出
这将产生以下结果 −

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP