框架 HTML iframe
请问我做一网页需要顶部div高度固定,宽度100%,下面放一个iframe框架
框架左侧div宽固定,高度100%,右侧宽高都是100%满屏显示,如屏幕小,右侧内容多的话则自动有滚动条,请问这要怎么做呢,在网上找了适应高度的都不行。
我随便测试的框架,右边的内容只显示一小部分,麻烦大虾们帮我看看,谢谢
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style>*{font-size:12px; margin:0; padding:0;}body,html{width:100%; height:100%;}.menu{ float:left;width:165px;height:41px;line-height:41px;font-size:16px;font-weight:bold;text-align:center;cursor:pointer;border-right:1px solid #dfdfdf;}.content{width:100%;height:100%;}.contentframe{width:100%;height:100%;}</style></head><body> <div style="width:100%; background:#CCCCCC; height:60px;"> <span class="menu menuBackground"><a href="1.htm" target="contentframe">栏目一</a></span> <span class="menu"><a href="2.htm" target="contentframe">栏目二</a></span> <span class="menu"><A href="3.htm" target="contentframe">栏目三</A></span> </div> <div class="content" id="content" > <iframe scrolling="no" frameborder="0" src="1.htm" class="contentframe" name="contentframe" id="contentframe"></iframe> </div></body></html>
1.htm 页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style><style>*{font-size:12px; margin:0; padding:0;}body,html{width:100%; height:100%;margin:0; padding:0;}.content{width:100%;height:100%;}.contentframe{width:100%;height:100%;}</style></head><body><div style="width:250px; height:100%; float:left; background:#99C"> <a href="2.htm" target="rightframe">fsdf</a><br /> <a href="3.htm" target="rightframe">fsfsafsa</a></div><div style=" float:left; background:#960; height:100%; position:relative"> <div class="content" id="content" > <iframe scrolling="no" frameborder="0" src="2.htm" class="contentframe" name="rightframe" id="rightframe"></iframe> </div></div></body></html>
2.htm 页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style><style>*{font-size:12px; margin:0; padding:0;}body,html{width:100%; height:100%;margin:0; padding:0;}</style></head><body > <div style="height:100%; width:100%; background:#ccc;">2页面内容</div></body></html>
回复讨论(解决方案)
div的自动撑满跟td不一样,不是左边250,右边100%就行的,需要自己计算一下div应有的宽度然后给相应的div设置。
你的1.html在load的时候判断一下浏览器的宽度,给content设置就行,简单的code如下,没有做详细的兼容性测试。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test</title> <style> body, html { width: 100%; height: 100%; margin: 0; padding: 0; } .content { width: 100%; height: 100%; } .contentframe { width: 100%; height: 100%; } </style> <script type="text/javascript"> function setContentWidth() { document.getElementById("content").style.width = document.body.clientWidth - 250 + "px"; } </script></head><body onload="setContentWidth();"> <div style="width: 250px; height: 100%; float: left; background: #99C"> <a href="2.htm" target="rightframe">fsdf</a><br /> <a href="3.htm" target="rightframe">fsfsafsa</a> </div> <div style="float: left; background: #960; height: 100%; position: relative"> <div class="content" id="content"> <iframe scrolling="no" frameborder="0" src="2.htm" class="contentframe" name="rightframe" id="Iframe1"></iframe> </div> </div></body></html>
谢谢,是可以显示的,但是右边内容多的话,超出部分都会被隐藏掉也就是不显示,拉滚动条也不能到底,这不知道怎么解决,
2.html中把iframe的scrolling设成yes就应该可以了,里面的内容太多就会滚动了。
谢谢,是可以显示的,但是右边内容多的话,超出部分都会被隐藏掉也就是不显示,拉滚动条也不能到底,这不知道怎么解决,
错了,是1.html中的iframe
还有一个建议,index.htm中的content的高度的100%继承的应该是body的高度,因此body的最终高度被撑到了document.body.clientHeight + 60,大于浏览器高度,因此不管右边frame里面的内容滚不滚,浏览器会一直有滚动条。
和上面的设置宽度的做法一样,可以改动index.htm页面,在load时content设一个高度。 同时为了避免body的滚动条,再加上overflow:hidden。
可以参考下面的code,这样整个页面也整洁一些。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style> * { font-size: 12px; margin: 0; padding: 0; } body, html { width: 100%; height: 100%; } .menu { float: left; width: 165px; height: 41px; line-height: 41px; font-size: 16px; font-weight: bold; text-align: center; cursor: pointer; border-right: 1px solid #dfdfdf; } .content { width: 100%; height: 100%; } .contentframe { width: 100%; height: 100%; } </style> <script type="text/javascript"> function setContentHeight() { document.getElementById("content").style.height = document.body.clientHeight - 60 + "px"; }</script></head><body onload="setContentHeight();" style="overflow: hidden;"> <div style="width: 100%; background: #CCCCCC; height: 60px;"> <span class="menu menuBackground"><a href="1.htm" target="contentframe">栏目一</a></span> <span class="menu"><a href="2.htm" target="contentframe">栏目二</a></span> <span class="menu"> <a href="3.htm" target="contentframe">栏目三</a></span> </div> <div class="content" id="content"> <iframe scrolling="no" frameborder="0" src="1.htm" class="contentframe" name="contentframe" id="contentframe"></iframe> </div></body></html>

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
