【问题标题】:Put an iframe on the right在右边放一个 iframe
【发布时间】:2021-01-04 17:48:36
【问题描述】:

所以我想为一个页面制作一个 iframe,该页面将显示一系列茶和凉茶,并且我希望左侧的选项在另一个 iframe 中。不过,我已经很久没有这样做了,而且我以前只用 DreamWeaver 做过(我没有经验,所以我遵循了老师的教程),所以软件生成了大部分代码,真的。有人可以帮我吗?现在,这是 iframe 的代码以及横幅:

    <div class="container">
        <img src="images/bannersite.png" alt="Banner" style="width:100%;">
        
        <div class="bigtxt" style="left: 100px; top: 70px; position: absolute;">
            <span style="color: #B3D1B3;">Ma</span><span style="color: #404040;">Thé</span>
        </div>
    </div>

    <iframe src="accueil.html" style="width: 99.8%;">
    </iframe>

它是这样的:

如您所见,下方有一个滚动条,这是因为出于某种原因,iframe 决定它会在横幅右端的左侧继续,而我不希望这样。我希望 iframe 和横幅都适合整个屏幕。

这是我想做但不知道如何做的事情:

感谢任何愿意帮助我的人。

【问题讨论】:

  • 欢迎来到 SO。我发布了一个包含 CSS 代码而不是内联 CSS 的解决方案。它是相同的,但它使用classes 而不是内联style=""。请查看 cmets,使用 codepen,如果您有任何问题,请告诉我。
  • 另外,使用我提供的代码,底部应该没有滚动条。但是,如果仍然存在,请尝试将此代码添加到 css:body{overflow-x:hidden}

标签: html iframe width


【解决方案1】:

请注意,iframe 不适合 SEO。最好使用 java 脚本或 jquery 驱动的代码片段。谷歌和其他人不信任 iframe,使您的网站评级下降很多。

【讨论】:

  • 感谢分享,其实我不知道!
  • 真的吗?不过,我不知道该怎么做。请问有在线教程吗?谢谢
  • 了解 ajax、Jquery、css3、html5 技术。如果您想要一个不错的网站,并且可以完全控制自己的意愿,那么您必须学习它们。至少您必须了解如何以正确和有效的方式使用它们。
【解决方案2】:

看看这个 codepen,我认为它可以满足您的需求。

https://codepen.io/larrytherabbit/pen/mdPGzdm

我稍微编辑了您的代码,请阅读我为您制作的 cmets,以便更好地理解新的代码行。有一个 HTML 代码和一个适用于它的 CSS 代码,以及类(它们以“.”开头)

HTML

<div class="container"> <!-- this is the container for the picture and the "MaThé" text -->
        <img src="https://images.all-free-download.com/images/graphicthumb/sunflower_background_03_hd_picture_165827.jpg" alt="Banner">
        <div class="bigtxt" style="left: 100px; top: 70px; position: absolute;">
            <span style="color: #B3D1B3;">Ma</span>
            <span style="color: #404040;">Thé</span>
        </div>
</div> <!-- top header container closes here -->

<div class="flex-container"> <!-- this is the container for the sidebar and the iframe on the right -->
  <div class="sidebar">
    <button>Button</button>
    <button>Button</button> 
    <button>Button</button>
  </div>
<iframe src="https://www.youtube.com/embed/sJIjIMMIoSw" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

CSS

.container img {
  width:100%;max-height:250px;
}

.bigtxt {
  font-size:50px;
}

.flex-container { /* the display attribute set to flex creates a "flexbox" display, please see here: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox */
  display:flex;width:100%;
}

.sidebar { /* this container is also set to flex, but here we change the flex-direction to column for the buttons to display in a column */
  display:flex;flex-direction:column;height:300px;justify-content:center;width:30%;align-items:center; /* giving a width of 30% to the sidebar, it will fill 30% of the available space, which is 100% of the window width as defined above */ /* by setting align-items and justify-content to "center" the buttons place themselves in the middle of the sidebar */
}

.sidebar button {
  margin:30px 0;max-width:100px; /* giving a bottom and a top margin ofo 30px to the buttons to space them apart */
}

iframe {
  width:70%; /* here we simply set the width of the iframe to the remaining space which is 70% of the 100% width of the .flexbox container */
}


【讨论】:

  • 非常感谢。这对我帮助很大。 30 px的边距;来回按钮没有显示。 30px 0 是什么意思?那个“0”是什么意思?我从来没有在我的边距值之后使用过 0。您是否碰巧知道如何为按钮编写代码(例如,一个按钮将是“tea”,它会在 iframe 中显示我的页面 tea.html 等)?
  • 这是结果,奇怪的是:zupimages.net/viewer.php?id=20/38/kf4m.png
  • @manouna 很高兴它有帮助。 margin:30px 0; 表示 = margin-top:30px;margin-bottom:30px;margin-left:0px;margin-right:0px。如果margin-top和margin-bottom的值相同,这只是一种更快的编码方式。
  • @manouna 我看到结果不是你想要的。请尝试创建 jsfiddle 或 codepen 并复制粘贴我的代码(来自 codepen codepen.io/larrytherabbit/pen/mdPGzdm),然后使用您的值更改值。告诉我这是否有效。
  • 另外,如果我的回答对您的问题有所帮助,请考虑将其标记为已接受的答案。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-02
  • 2021-08-10
相关资源
最近更新 更多