div自适应高度问题_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:47:21
Original
1135 people have browsed it


定义了如图三个div  上面div紧贴浏览器上部 下面div紧贴浏览器下部分 想让中间空白div自适应高度(就是中间留多少填多少) 该怎么做?

上下两个div是两个html 我include包含进来的


回复讨论(解决方案)

<!doctype html><html lang="en"><head>	<meta charset="UTF-8">	<title>页面名称</title><style type="text/css">html,body { 	height: 100%;	margin: 0;	padding: 0;}.class1 {	position: absolute;	background-color: #f60;	left: 0;	top: 0;	width: 100%;	height: 100px;}.class2 {	position: absolute;	background-color: #cc0;	left: 0;	top: 100px;	bottom: 100px;	width: 100%;}.class3 {	position: absolute;	background-color: #f60;	left: 0;	bottom: 0;	width: 100%;	height: 100px;}</style></head><body><div class="class1"></div><div class="class2"></div><div class="class3"></div></body></html>
Copy after login
Copy after login

如果上下两个div高度固定,可以js算出中间高度

<!doctype html><html lang="en"><head>	<meta charset="UTF-8">	<title>页面名称</title><style type="text/css">html,body { 	height: 100%;	margin: 0;	padding: 0;}.class1 {	position: absolute;	background-color: #f60;	left: 0;	top: 0;	width: 100%;	height: 100px;}.class2 {	position: absolute;	background-color: #cc0;	left: 0;	top: 100px;	bottom: 100px;	width: 100%;}.class3 {	position: absolute;	background-color: #f60;	left: 0;	bottom: 0;	width: 100%;	height: 100px;}</style></head><body><div class="class1"></div><div class="class2"></div><div class="class3"></div></body></html>
Copy after login
Copy after login


如果中间再放一张图片  怎么让它自然充满整个div 可以失真 但是要充满这个div

class2  的高度=屏幕的高度-class1.height-class2.height
浏览器的可视高度:$(widow).height()
class1高度:$(".class1").height()
class3高度:$(".class3").height()
var class2height=$(widow).height()-$(".class1").height()-$(".class3").height();
赋值给class2样式高度   $(".class2").css("height",class2height+"px")

如果中间再放一张图片  怎么让它自然充满整个div 可以失真 但是要充满这个div


设置背景图片啊,图片尺寸设置为contain就充满整个div了
background: url("url") contain contain;

//中间空白div自适应高度


    

    

    

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!