https://jsfiddle.net/mktrywLr/205/ 这个例子是左右的固定和可变 参考这个方法想做个上面固定,下面可变的页面 试了下不灵,请指教
https://jsfiddle.net/mktrywLr/205/ 这个例子是左右的固定和可变 参考这个方法想做个上面固定,下面可变的页面 试了下不灵,请指教
|
bzw875Dec 11, 2017
1
html,body {
height: 100%; } #a { height: 300px; background-color: #fde2e2; } #b { height: 60%; background-color: #d1daf3; } <div id="a">a</div> <div id="b"></div> 所有父元素都有指明高度,否则是父元素 height:auto,自动撑高,子元素无法计算百分比 |
|
3
|
|
4
你想
height:calc(??% - ??px); 还是? height:calc(?? * (100% - ??px)); |
|
5
不考虑兼容性用 flex 布局是最简单的
|
|
6
|
|
7
<!DOCTYPE html>
<html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <style> *{margin:0px;padding: 0px;} .top{height:300px;background: red;} .bottom{position: absolute;top:300px;background: yellow;bottom:0px;width: 100%;} </style> <body> <div class="top"></div> <div class="bottom"></div> </body> </html> |
|
10
@yangheng4922 能参考我的例子,改成上下模式模式的吗
|
|
overflowHiddenDec 11, 2017
11
|
|
wxsmDec 11, 2017
12
一个简单的做法:上面那块用 absolute position,下面那块 100% 高,然后 padding-top 等于上面的高度。
|
|
dud1aoDec 12, 2017
14
@sunhk25 我 7 楼发的用不了吗?? 上方固定高度 下方 absolute 设置 top 为上方的高度 bottom 为 0px 这样下面的 div 就是自适应的
|
|
15
Bottom 会超过父元素
|