Footer displays within the content section

Currently, I am utilizing Next.js and antd's layout components to create a dashboard-style page using their Layout component. However, I have encountered two issues related to styling (CSS) in this setup:

  • Footer appearing within the Content: I am working on a modified version of the fixed-sider example from the antd documentation. The Footer is ending up between the Content components. It seems like a styling issue, but I am struggling to pinpoint the exact problem. What kind of styling issue should I be focusing on to resolve this?
  • Scrolling behavior: When fully expanded, the Sidebar cannot be scrolled all the way to the end. Instead, the browser window scrollbar needs to be used to navigate through the fixed sidebar content completely. Is there a way to disable the window's scrollbar (which also affects the appearance)? If disabling it is not an option, how can I make the sidebar scrolling smooth and independent from the browser window scrollbar?

I have recreated the problem in this CodeSandbox demo.

https://i.stack.imgur.com/6lGk5.png

Answer №1

The issue at hand is a result of the interaction between multiple <Layout /> components and their children, particularly when they have varying heights. It seems that child Layout and Content components inherit height from the parent Layout, or at least have a smaller height.

Your current Layout setup looks like this (pseudocode):

<Layout>
  <Layout restrictedHeight >
    <Layout inheritedRestrictedHeight>
      <Content inheritedRestrictedHeight >
        <div unrestrictedHeight />
      </Content> //Content "height" ends here
      <Footer fixedPosition /> //Always begins where Content ends
      //Div "height" ends here
    </Layout>
  </Layout>
</Layout>

The footer is implemented in such a way that it is placed after the Content in the DOM, but since the large div's height is not restricted, it extends far below the Content container. This results in the Footer component appearing to render within the content.

The issue lies with this line:

<Layout hasSider={true} style={{ height: "100vh", marginTop: 64 }}>

By setting the height property to 100vh (100% view height), you are effectively limiting the layout to the current pixel count available on the screen vertically. To address this, set the height to 100% instead of 100vh:

<Layout hasSider={true} style={{ height: "100%", marginTop: 64 }}>

This adjustment resolves the double scroll bar issue as well.

UPDATE AND SOLUTION FOR NONSCROLLING SIDEBAR

To prevent the sidebar from scrolling, give the Sider component a specific height equivalent to what is visible on the screen.

The component renders in the DOM with a height based on its contained content. To achieve a non-scrolling sidebar, limit the height to the space below the navigation bar by calculating 100vh minus the nav bar's size in the CSS/LESS for the sidebar: height: calc(~"100vh - 64px"); and ensure overflow-y is set to auto.

.sidebar {
  overflow-y: auto;
  overflow-x: hidden;
  height: calc(~"100vh - 64px");
  position: fixed;
  left: 0;
} 

For an updated solution, refer to this codesandbox.

In future queries, it is recommended to focus on one main question for better responses.

Answer №2

The solution is to reposition the footer between lines 119 and 120, ensuring it aligns with the sidebar within the same container.

Answer №3

Regrettably, I am unable to make changes to your script. Upon reviewing it, my recommendation would be to insert the following code snippet:

<Footer style={{ textAlign: "center" }}>
            Ant Design ©2018 Created by Ant UED
          </Footer>

After the layout tag.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Indubitably, validation for a field that appears based on the condition of a prop

I am currently utilizing react-hook-form along with YUP for client-side validations. One specific situation involves receiving a prop from the backend, which determines whether an input field should be marked as required upon form submission. If the prop i ...

The use of backticks within an HTML document for nesting purposes is not permitted

Currently, I am utilizing nodemailer to send HTML template code in Node.js. However, the issue I am encountering is that I cannot nest backticks within it: Here's my code snippet: let mailDetails={ from: 'example@example.com', to: & ...

Tips for extracting URL parameter values in React applications

Here is a component that allows for searching: import { ChangeEvent, useCallback, useState } from 'react'; export function SearchComponent() { const [searchValue, setSearchValue] = useState<string>(''); const updateSearchValu ...

Iterate through an array index within a map function in a ReactJS component

I am working with a map that contains images of metros, and I need to increment the number by 1 at each loop iteration. For example, the first loop will display {metrosImages[0]}, then {metrosImages[1]}, and so on until the loop reaches its end. The code ...

Eliminate the grey border located above the arrow in the Bootstrap tooltip

Is there a reason why a thin border is showing up on all of my Bootstrap tooltips? I have looked extensively for answers but have not been able to find anyone else having the same issue. This border appears consistently in all of our MVC projects, and we h ...

Formcontrol is not functioning properly with invalid input

I am attempting to style an input field with a FormControl using the :invalid pseudo-class. Here is my code snippet: scss input:invalid { background-color: red; } html <input type="text" [formControl]="NameCtrl"> Unfortunate ...

Steps for allowing the cells in a Data-Table column to be edited

Is it possible to have editable cells in a column of a Data Table with the support of the plugin? ...

Align the items in the center of a Bootstrap navigation bar

I am looking to center the navigation menu items on my navbar. Currently, my navbar layout appears like this: Specifically, I want "Users", "Admin", and "Records" to be centered within the navbar. Additionally, I would like to adjust the alignment of the ...

"Troubleshooting: Why is TailwindCSS not functioning correctly in my NextJS

My project utilizes a combination of NextJS, TailwindCSS, and Typescript. Strangely, everything displays correctly in the development environment, but once in production, the tailwindcss classes are not being applied. For reference, here is the link to t ...

Deactivating one div's class upon clicking on another div

Below is the HTML code snippet: <div class="container"> <ul class="navbar"> <li class="nb-link"><a>Home</a></li> <li class="dropdown"> <a>CBSE</a> <ul class="dropdown-menu"&g ...

Position an element to the right inside its parent container with varying width in Internet Explorer 7 or earlier

I am trying to align a button to the right edge of a table inside a container-div that has no set width. The goal is to have the button float on the right side of the table, lining up with its right edge. While my current approach works in most browsers, i ...

I seem to be having trouble with jQuery. Every time I try to submit my form, nothing happens

I am currently working on creating a web page for a numerical game, but I am facing difficulties with my jQuery implementation. Despite checking all my placements, nothing seems to happen when I click on the Submit button. Any assistance would be greatly a ...

The resource was treated as an image but sent with the MIME type application/octet-stream

Upon accessing my webpage, a warning message is displayed: Resource interpreted as Image but transferred with MIME type application/octet-stream The images on my page are in JPEG format. The server writes the image bytes to an output stream and sends it ...

Troubleshooting problems with Flask's render_template()

I've been working on a Flask web application that requires users to be logged in to access the contents and functionalities. However, I've encountered an issue where, sometimes after logging in, instead of loading the full home page, a blank "abo ...

Load HTML 5 video on a webpage after all other elements have finished loading

Hello there! I'm trying to figure out a way to load an HTML 5 video after the page has already loaded. Currently, the video pauses all site interaction until it's fully loaded, but I'd prefer to have it display an image first and then autopl ...

How can I target an element with inline styling using CSS?

How can I target headings with inline style 'text-align: center' in my CSS so that I can add ::after styling to them? This is for a WordPress CMS, specifically to modify content in the WYSIWYG editor used by clients. Here's an example of th ...

Is there a reason why Social Bar isn't appearing at the top?

My challenge is to position the bar close to the black footer. It appears correctly in Chrome, but not in Firefox and Opera. The screenshot shows how it looks in Chrome. However, in Firefox and Opera, the social bar is positioned lower and does not align ...

What is the exclusive method for gaining access to the page limited only to Admin?

Is there a way to restrict access to /page/admin in my project only to administrators? Here is the code in my module config: auth : authRoles.admin, routes : [ { path : '/page/admin', component: React.lazy(() => i ...

React Redux failing to correctly map the action to props

I have a function called updateChapter that is responsible for updating the database. I have included this function in my component named EditChapter. However, when I checked the props of the component, the updateChapter action was missing. In another com ...

Changing Image Size in Real Time

Trying to figure out the best way to handle this situation - I need to call a static image from an API server that requires height and width parameters for generating the image size. My website is CSS dynamic, adapting to different screen sizes including ...