gpt4 book ai didi

html - 包含 PDF 的 iFrame 的布局问题

转载 作者:行者123 更新时间:2023-11-28 03:35:29 26 4
gpt4 key购买 nike

我将 MVC 4 与 Bootstrap 用于我正在开发的网站。相当简单的布局,我有一个位于顶部的 Bootstrap 导航栏 (navbar-fixed-top),然后我有一个页面标题,一个具有绝对位置和高度的 div,就在菜单下方。

然后对于页面内容,我有一个 div,同样具有绝对位置,其顶部设置为它从页面标题下方开始。 body 上的溢出设置为无,页面内容上设置为自动。

body, html
{
height: 100%;
overflow: hidden;
}

.PageTitle
{
position: absolute;
top: 40px;
left: 0;
right: 0;
height: 60px;
color: #fdf4f4;
background-color: #4266cd;
border-color: #bce8f1;
}

.Content
{
overflow: auto;
position: absolute;
top: 100px;
left: 0;
right: 0;
bottom: 0;
}

这适用于其他页面,但我需要显示每月传单 (PDF) 并希望它填充内容区域并允许用户滚动它。问题当然是,如果我添加一个 100% 高度的 iFrame,它会占用内容 div(它的父级)的高度,这就是浏览器窗口的高度。如果我能告诉它把高度设置为 100% - 100px,那就太酷了。

我曾尝试使用 jQuery 更改大小,但没有成功。

有人有一些想法可以帮助我吗?

谢谢。

更新:我阅读了 Akshay Khandelwal 的帖子并创建了一个简单的 HTML 页面,其中包含我想要做的基础知识。在重现我之前遇到的问题的过程中,我可能已经找到了解决方案。看起来下面的代码有效。不确定这是否是一个好方法。

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PDF View Test</title>

<style>
body
{
margin: 0;
overflow: hidden;
}

.NavBarTop
{
position: fixed;
top: 0;
left: 0;
right: 0;
height: 40px;
margin-bottom: 0;
background: #778899;
}

.PageTitle
{
position: absolute;
top: 40px;
left: 0;
right: 0;
height: 60px;
color: #fdf4f4;
background-color: #4266cd;
border-color: #bce8f1;
}

.Content
{
overflow: hidden;
position: absolute;
top: 100px;
left: 0;
right: 0;
bottom: 0;
}

h3
{
color: rgb(253, 244, 244);
display: block;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 25px;
font-weight: bold;
height: 40px;
line-height: 40px;
margin-bottom: 10px;
margin-left: 0;
margin-right: 0;
margin-top: 10px;
text-align: center;
}

h4
{
color: rgb(253, 244, 244);
display: block;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 20px;
font-weight: bold;
height: 20px;
line-height: 20px;
margin-bottom: 5px;
margin-left: 0;
margin-right: 0;
margin-top: 10px;
text-align: center;
}

iframe
{
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="NavBarTop">
<h4>This is the menu bar.</h4>
</div>

<div class="PageTitle">
<h3>The Page Title</h3>
</div>

<div class="Content">
<iframe src="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/content-server/pdfs/adobe-ebook-platform-whitepaper.pdf"/>
</div>
</body>
</html>

最佳答案

我找到了我所问问题的答案,尽管我不相信这是最好的方法。为了完整起见,这里的 HTML 将为您提供一个嵌入网页的 PDF,其中滚动条仅滚动 PDF 文档而不滚动页面标题和菜单。

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PDF View Test</title>

<style>
body
{
margin: 0;
overflow: hidden;
}

.NavBarTop
{
position: fixed;
top: 0;
left: 0;
right: 0;
height: 40px;
margin-bottom: 0;
background: #778899;
}

.PageTitle
{
position: absolute;
top: 40px;
left: 0;
right: 0;
height: 60px;
color: #fdf4f4;
background-color: #4266cd;
border-color: #bce8f1;
}

.Content
{
overflow: hidden;
position: absolute;
top: 100px;
left: 0;
right: 0;
bottom: 0;
}

h3
{
color: rgb(253, 244, 244);
display: block;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 25px;
font-weight: bold;
height: 40px;
line-height: 40px;
margin-bottom: 10px;
margin-left: 0;
margin-right: 0;
margin-top: 10px;
text-align: center;
}

h4
{
color: rgb(253, 244, 244);
display: block;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 20px;
font-weight: bold;
height: 20px;
line-height: 20px;
margin-bottom: 5px;
margin-left: 0;
margin-right: 0;
margin-top: 10px;
text-align: center;
}

iframe
{
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="NavBarTop">
<h4>This is the menu bar.</h4>
</div>

<div class="PageTitle">
<h3>The Page Title</h3>
</div>

<div class="Content">
<iframe src="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/content-server/pdfs/adobe-ebook-platform-whitepaper.pdf"/>
</div>
</body>
</html>

关于html - 包含 PDF 的 iFrame 的布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14663065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com