Text will be positioned between the Header and Footer

The text positioned between the header and footer elements is flowing beneath them. I attempted to use flex-start and flex-end on both the header and footer, but they do not align to the absolute top. Instead, they are positioned above and below the content.

The CSS style for the header is as follows:

.Header {
  width: 100%;
  position: absolute;
  top: 0;
  flex-wrap: wrap;
}

The CSS style for the footer is as follows:

.Footer {
  width: 100%;
  position: absolute;
  bottom: 0;
  flex-wrap: wrap;
}

If it helps, here is the CSS style for the content:

.Content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

Answer №1

When elements are absolutely positioned, they are removed from the normal flow of the document.

To create space for a header and footer, you can add margins to the top and bottom of the content. Another option is to switch to using "sticky" positioning, which can be achieved with the following CSS:

.Header {
  position: sticky;
  top: 0;
}
.Footer {
  position: sticky;
  bottom: 0;
}

Answer №2

Your current header is positioned using position: absolute, causing it to be out of the normal flow of elements. Consider changing it to position: relative or adding a top padding/margin equal to the height of your header on the content area.

.header {
  width: 100%;
  position: absolute;
  top: 0;
  flex-wrap: wrap;
  background: #707070;
  height: 100px;
}

.footer {
  width: 100%;
  position: absolute;
  bottom: 0;
  flex-wrap: wrap;
  background: #e9e;
}

.content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: blue;
  margin-top: 100px;
  
}
<body>
  <div class="header">
    <h1>Header</h1>
  </div>
  <div class="content">
    <h2>Content</h2>
  </div>
  <div class="footer">
    <h2>Footer</h2>
  </div>
</body>

Answer №3

check out this demonstration

HTML

<body>
  <div class="Header">Header</div>
  <div class="Content">Content</div>
  <div class="Footer">Footer</div>
</body>

CSS

body{
  margin:0;
  padding:0;
  }

.Content {
  background-color:red;
  height:90vh;
  width: 100vw;
}

.Footer {
  background-color:green;
  width: 100vw;
  bottom: 0;
    height:5vh
}

.Header {
  background-color:blue;
  width: 100vw;
  top: 0;
  height:5vh
}

To learn more about The position Property, visit : https://www.w3schools.com/css/css_positioning.asp

Answer №4

One option is to provide padding at the top and bottom of the content that matches the height of both the header and footer.

.Content {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
overflow-y: auto;
}

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

What is preventing me from obtaining the select and input values?

I'm currently facing an issue where I am unable to retrieve the values of customInput and customSelect and store them in the state. The challenge arises when trying to integrate these components into a react dashboard material-ui setup. Strangely, whe ...

Utilizing numerous Rails API POST requests has become a common practice

Currently, my ReactJS application is connected to a Rails 5 API. The React application sends a single JSON POST request to api/v1/job in order to create a new job record. This request contains information for two HABTM relationships with Tools and Technol ...

Unlocking the mysteries of cookies in React Native ExpoDiscovering the secrets

As a newcomer to React Native and Expo, I find myself puzzled by how cookies are handled. I have an Express server that assigns a token cookie in a response (res.cookie("jwt",token)). Strangely, when my React Native client sends an authentication ...

What are the steps to create a dynamic grid interface using Bootstrap 5?

I attempted to use the code below but it did not work: <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"/> <div class="container-fluid"> <div class="row"> <div c ...

Leveraging the results from a static React function

I am currently working on a React + Webpack project that supports JavaScript ECMAScript 6. Here is the code snippet I am trying to implement: class ApiCalls extends React.Component{ static uploadFiles(files) { // upload code if(success) { ...

Having trouble with the anchor tag not functioning properly

I'm looking to create a unique video experience by having an iframe video play automatically and opening a third-party video player in a lightbox style when clicked. Currently, the video autoplays, but I want it so that when the user clicks on the vi ...

What is the best way to use jQuery to set the height of one div equal to another div

Edited: I am facing a situation with a 3-column layout - Column A, Column B, Column C. The height of Column A is dynamic and I need to set the same height for both Column B and C. For instance, Column A contains a tabbed panel with varying heights based ...

Is it possible to impose dimensions on a content-editable div?

Is there a way to make a content editable div act like a text box with a fixed horizontal width and unlimited vertical expansion? Take a look at this jsfiddle, and find the code below: http://jsfiddle.net/seoj7cgq/ <!--How do I force the text to stay ...

Data structures of advanced complexity within HTML data attributes

I am delighted by the existence of the html5 data attribute. It's great to be able to input a plain string into html attributes and retrieve them using jquery. However, wouldn't it be wonderful to have more than just a basic string? Is there a ...

Trouble with JavaScript loading in HTML webpage

<!DOCTYPE html> <html> <head> <title>Breakout Game</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <canvas width="900" height="450" class="canvas"></canvas> ...

Different Ways to Conceal a Div Element Without Using Jquery

One interesting feature of my website is that users can select audio from a drop-down box, triggering the $.post function to display an auto-playing audio player in a div. However, I'm facing a problem because I don't want the audio player to be ...

``Why is the default value not appearing in the Autocomplete set?

I'm having trouble setting a default value in my autocomplete field. I am fetching select options from the database with this code: let films = await db.collection("films").find().toArray(); This is the data that is returned: [ 0: { title ...

The dropdown menu is not being displayed, and instead the title is showing a message that says "Nothing Selected." Please review the code for any

I've been attempting to automatically select an option in a dropdown menu, but for some reason it's not displaying the dropdown and instead showing "Nothing Selected" as the title. I tried using opt.setAttribute("selected", "selected"); in my cod ...

Special react-hook designed for dynamically assigning CSS classes

I'm currently exploring React's hooks and playing around with reusing the ability to add a shadow to an element (utilizing bootstrap as the css-framework). Here is the current structure of my App: export const App: React.FunctionComponent<IA ...

Issues with external javascript link functionality

I'm having trouble connecting my external JavaScript file to my HTML code. I'm attempting to concatenate two strings using an input function and then display the new string in the empty text field. What could be causing this issue? Appreciate an ...

Prevent Symfony2 Twig from rendering HTML content

Is there a way to disable the rendering of HTML responses in Twig? I am currently working on a RESTful API and my goal is to completely prevent HTML rendering. For instance, if I access /foo/bar without an oAuth Access Token, Symfony2 should reply with a ...

How to output a string in jQuery if it includes a certain character?

I need to extract all strings that include a specific word within them, like this: <div> <div> <span> <h3>In Paris (Mark Bartels) worked for about 50 years.</h3> </span> </div> ...

The fixed navigation bar shows a flickering effect while scrolling at a slow pace

Currently facing a challenge with our sticky navigation. Noticing a flickering issue on the second navigation (sticky nav) when users scroll down slowly. The problem seems to be specific to Chrome and Edge, as it doesn't occur on Firefox, IE11, and S ...

Encountering issues with Axios while making a CORS request

I need to send an authentication cookie to an Express server. The request should include both a JWT from localStorage (which it does) and a previously set cookie. The cookie is set using the following response from an endpoint: res .cookie("cooki ...

Setting child div to match the parent div's height at 100% - here's how!

This is the layout of the page Here's the code snippet: <div class="newsContent row"> <div class="newsDate col-md-2">05 August 2014</div> <div class="newsSeparator col-md-1"> </div> <div class="newsDe ...