嵌入定位

问题描述 投票:0回答:1

我目前正在尝试将嵌入置于图像和屏幕中心之间。为此,我利用 https://rss.app/ 将 Google 新闻的 NBA 部分嵌入我的网站。如果您需要 CSS 文件,请随时询问。我已经苦苦挣扎了一段时间,非常感谢您能提供的任何帮助。

<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
</head>

<body>

  <nav class="navbar">
    <div class="content">
      <div class="logo">
        <a href="home.html">Home</a>
      </div>
      <ul class="menu-list">
        <div class="icon cancel-btn">
          <i class="fas fa-times"></i>
        </div>
        <li><a href="home.html">Home</a></li>
        <li><a href="news.html">News</a></li>
        <li><a href="records.html">Records</a></li>
        <li><a href="games.html">Games</a></li>
        <li><a href="images.html">Images</a></li>
      </ul>
      <div class="icon menu-btn">
        <i class="fas fa-bars"></i>
      </div>
    </div>
  </nav>
  <div class="banner">
    <div style="margin-top: 1000;">
      <rssapp-carousel id="8ywhL4ZjvQvQv5Zz"></rssapp-carousel>
      <script src="https://widget.rss.app/v1/carousel.js" type="text/javascript" async></script>
    </div>
  </div>
  <div class="about">
    <script>
      const body = document.querySelector("body");
      const navbar = document.querySelector(".navbar");
      const bannerTitle = document.querySelector(".bannerTitle");
      const menuBtn = document.querySelector(".menu-btn");
      const cancelBtn = document.querySelector(".cancel-btn");
      menuBtn.onclick = () => {
        navbar.classList.add("show");
        menuBtn.classList.add("hide");
        body.classList.add("disabled");
      }
      cancelBtn.onclick = () => {
        body.classList.remove("disabled");
        navbar.classList.remove("show");
        menuBtn.classList.remove("hide");
      }
      window.onscroll = () => {
        this.scrollY > 20 ? navbar.classList.add("sticky") : navbar.classList.remove("sticky");
        this.scrollY > 20 ? bannerTitle.classList.add("sticky") : bannerTitle.classList.remove("sticky");
      }
    </script>


</body>

</html>```
html position rss embed
1个回答
1
投票

如果我没理解错,这是你想要的行为吗?

https://jsfiddle.net/u2qtnLkv/

   <html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
</head>

<body>

  <nav class="navbar">
    <div class="content">
      <div class="logo">
        <a href="home.html">Home</a>
      </div>
      <ul class="menu-list">
        <div class="icon cancel-btn">
          <i class="fas fa-times"></i>
        </div>
        <li><a href="home.html">Home</a></li>
        <li><a href="news.html">News</a></li>
        <li><a href="records.html">Records</a></li>
        <li><a href="games.html">Games</a></li>
        <li><a href="images.html">Images</a></li>
      </ul>
      <div class="icon menu-btn">
        <i class="fas fa-bars"></i>
      </div>
    </div>
  </nav>
  <div class="banner bannerTitle">
    <div style="margin-top: 1000;">
      <rssapp-carousel id="8ywhL4ZjvQvQv5Zz"></rssapp-carousel>
      <script src="https://widget.rss.app/v1/carousel.js" type="text/javascript" async></script>
    </div>
  </div>
  <div class="about">
    <script>
      const body = document.querySelector("body");
      const navbar = document.querySelector(".navbar");
      const bannerTitle = document.querySelector(".bannerTitle");
      const menuBtn = document.querySelector(".menu-btn");
      const cancelBtn = document.querySelector(".cancel-btn");
      menuBtn.onclick = () => {
        navbar.classList.add("show");
        menuBtn.classList.add("hide");
        body.classList.add("disabled");
      }
      cancelBtn.onclick = () => {
        body.classList.remove("disabled");
        navbar.classList.remove("show");
        menuBtn.classList.remove("hide");
      }
      window.onscroll = () => {
        this.scrollY > 20 ? navbar.classList.add("sticky") : navbar.classList.remove("sticky");
        this.scrollY > 20 ? bannerTitle.classList.add("sticky") : bannerTitle.classList.remove("sticky");
      }
    </script>
    </div>

</body>

</html>

CSS:

rssapp-carousel {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh; /* ajuste a altura conforme necessário */
}

请记住,您的标签

<div class="about">
缺少结束标签。还要记住,类
bannerTitle
没有被使用,这可能会破坏请求它的 javascript。

© www.soinside.com 2019 - 2024. All rights reserved.