实现效果:网页窗口在缩放过程中,三栏布局两边的盒子宽度是固定的,中间的盒子的宽度是自适应的。
1.margin负值+float
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>title>
- <style>
- .container {
- padding-left: 100px;
- padding-right: 100px;
- }
-
- .container div {
- float: left;
- }
-
- .main {
- width: 100%;
- height: 200px;
- background-color: pink;
- }
-
- .left {
- position: relative;
- left: -100px;
- width: 100px;
- height: 200px;
- margin-left: -100%;
- background-color: skyblue;
- }
-
- .right {
- width: 100px;
- height: 200px;
- margin-right: -100px;
- background-color: aqua;
- }
- style>
- head>
- <body>
- <div class="container">
- <div class="main">div>
- <div class="left">div>
- <div class="right">div>
- div>
- body>
- html>
2.flex布局实现
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>title>
- <style>
- .container {
- display: flex;
- }
-
- .left {
- width: 200px;
- height: 200px;
- background-color: pink;
- }
-
- .right {
- width: 200px;
- height: 200px;
- background-color: skyblue;
- }
-
- .center {
- flex: 1;
- height: 200px;
- background-color: purple;
- }
- style>
- head>
- <body>
- <div class="container">
- <div class="left">div>
- <div class="center">div>
- <div class="right">div>
- div>
- body>
- html>