嵌入定位
P粉709644700
P粉709644700 2023-09-15 00:14:35
0
1
656

我目前正在尝试将嵌入内容置于图像和屏幕中心之间。为了实现这一目标,我利用 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>```

P粉709644700
P粉709644700

全部回复(1)
P粉267791326

如果我理解正确的话,这是你想要的行为吗?

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 */
}

请记住,您的标签

缺少结束标签。另请记住,bannerTitle 类未被使用,这可能会破坏请求它的 javascript。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板