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

标签 html css iframe

我将 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/

相关文章:

javascript - 如何使 Raphael js 打印方法在本地计算机上适用于法语、德语等字符?

java - 在 Bukkit 插件中从网页获取 HTML 字符串

html - 菜单不起作用

html - 使用 float 时水平溢出不起作用

jquery - 如何调整 jquery DatePicker 弹出窗口的位置以避免 iFrame 剪切

html - Flex align-self 属性在具有 align-items : baseline 的父项中不起作用

html - 选择类的所有子元素。 CSS

css - 默认情况下,Bootstrap 3 自动居中并自动填充整个页面?

html - 当 iframe 显示 :block; 时,如何并排放置 iframe 和 div

javascript - 允许子域之间的跨站点请求而不更改第二个子域的文件内容