如何将我的页面的内容保持在Navbar下方,无论屏幕高度如何?

发布于 2025-01-21 07:24:01 字数 1013 浏览 2 评论 0原文

我正在尝试将主页的内容放在页面中心的Navabr下方。 我能够将内容放在Navbar下方,但是当我更改窗口的高度时,它会更改。 如何使其在Navbar下方贴上? 这是CSS:

.content {
    position: relative;
    height: 100vh;
    transition: 0.3s;
}

.homeNav {
    transition: 0.3s;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
}

.homeContent {
    position: absolute;
    transition: 0.3s;
    top: 65%;
}

这是我的HTML:

<body>
    <div class="container content">
        <nav class="homeNav" id="all">
            <img src="/images/400x200.png" class="img-fluid mx-auto d-block" />
            <div class="row bg-info">

             NAVIGATION BAR HERE

            </div>
        </nav>
        <div id="main-page" class="homeContent">
        </div>
    </div>
</body>

请注意,这是一个单页应用程序,主页的内容是从单独的HTML文件中获得的。

I am trying to place the content of my homepage below my navabr which is located at the center of the page.
I was able to place the content below the navbar, but it changes when I change the window's height.
How do I make it stick below the navbar?
this is the css:

.content {
    position: relative;
    height: 100vh;
    transition: 0.3s;
}

.homeNav {
    transition: 0.3s;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
}

.homeContent {
    position: absolute;
    transition: 0.3s;
    top: 65%;
}

This is my html:

<body>
    <div class="container content">
        <nav class="homeNav" id="all">
            <img src="/images/400x200.png" class="img-fluid mx-auto d-block" />
            <div class="row bg-info">

             NAVIGATION BAR HERE

            </div>
        </nav>
        <div id="main-page" class="homeContent">
        </div>
    </div>
</body>

Please note that this is a single-page application, and the content of the main-page is obtained from a separate HTML file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许你一世情深 2025-01-28 07:24:01

身体元素中

body{
  margin-top: 200px;
}

您可以将CSS添加到IT的 。
另外,您可以将标题和底部内容包裹在div中,然后将保证金top给予该div元素。

<div class="wrapper">
   <nav>Header Area</nav>
   <!-- Everything else goes here -->
</div>

包装班的CSS:

.wrapper{
   margin-top: 200px;
}

You can add css to the body element

body{
  margin-top: 200px;
}

That's it.
Alternatively, you can wrap the header and bottom content in a div and then give margin-top to that div element.

<div class="wrapper">
   <nav>Header Area</nav>
   <!-- Everything else goes here -->
</div>

CSS for wrapper class:

.wrapper{
   margin-top: 200px;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文