search
HomeWeb Front-endHTML Tutorial急求解:iframe框架不能100%显示问题_html/css_WEB-ITnose

框架 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>

Statement
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
What are boolean attributes in HTML? Give some examples.What are boolean attributes in HTML? Give some examples.Apr 25, 2025 am 12:01 AM

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values ​​need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

How can you validate your HTML code?How can you validate your HTML code?Apr 24, 2025 am 12:04 AM

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML vs. CSS and JavaScript: Comparing Web TechnologiesHTML vs. CSS and JavaScript: Comparing Web TechnologiesApr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools