Text will not be visible within the div container

I'm working on a mobile layout design for my css project. My goal is to have the header and footer remain fixed on the screen while allowing users to scroll through the content in between. I was able to achieve the fixed positioning, but now none of my text is showing up.

body {
  width: 21em;
}

.header,
.footer,
.content {
  display: flex;
  flex-direction: row;
}

.header,
.footer {
  z-index: 2;
}

.header {
  position: fixed;
  width: 100%;
  height: 30%;
  background-color: red;
}

.content {
  position: absolute;
  width: 100%;
  height: 500%;
  clear: both;
  text-align: center;
}

.footer {
  position: fixed;
  width: 100%;
  height: 30%;
  background-color: green;
  margin-top: 120%;
}
<div class='header'></div>
<div class='content'>
  <p>
    Despite facing challenges during his childhood, he always felt loved and protected by his mother. Family was everything to her, and this dedication resonated deeply with her son. His faith became an integral part of his life, which he gladly shared with others. He found comfort in accepting the teachings of missionaries, leading him to strengthen his faith, be baptized, and receive the gift of the Holy Ghost. He emphasized that following Christ is simple yet profound.
  </p>
</div>
<div class='footer'></div>

Answer №1

To ensure the content is properly positioned, apply a margin-top to the body and set top: 0; for the header to keep it at the top consistently.

Simply adjust the margin as needed to achieve your desired layout.

body {
  width: 21em;
  margin-top:20%;
}

.header,
.footer,
.content {
  display: flex;
  flex-direction: row;
}

.header,
.footer {
  z-index: 2;
}

.header {
  position: fixed;
  width: 100%;
  height: 30%;
  background-color: red;
  top: 0;
}

.content {
  position: absolute;
  width: 100%;
  height: 500%;
  clear: both;
  text-align: center;
}

.footer {
  position: fixed;
  width: 100%;
  height: 30%;
  background-color: green;
  margin-top: 120%;
}

<div class='header'></div>
<div class='content'>
  <p>
    Despite facing adversity in his youth, a young man found solace in his mother's love and unwavering protection. Family values were deeply ingrained in him, and he now shares his newfound faith with others, born from his strong belief in the message of missionaries. Accepting this message was a life-changing experience that reinforced his commitment to following Christ unconditionally.
  </p>
</div>
<div class='footer'></div>

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

Steps for accessing an image from the static folder in a Python-Django application

I am currently working on a portfolio website project where I am using html, css, js, and django. However, I am facing an issue with loading an image from the assets folder within the static directory. Here is a snippet of the template code causing the pr ...

Astro Project experiencing issues with loading SRC folder and style tags

After setting up a brand new astro repository with the following commands: npm create astro@latest npm run dev I encountered an issue where the default project template failed to display correctly on my computer. Here is how the page appeared: https://i. ...

Populate the div with an image that stretches to the full height

I'm facing an issue with my website's front page design, where a div is divided into two sections using the Twitter Bootstrap grid system. When the second grid (span9) is taller than the first (span3), the image perfectly fills up the span9 area ...

Displaying a dropdown selection that showcases two object properties lined up side by side

I need the select option dropdown values to display employee names along with their titles in a lined up format. For instance, if my values are: Bob Smith Director Mike Kawazki HR Jane Doe Manager I want them to be shown as: Bob Smith Director Mi ...

Is it feasible to incorporate two distinct images into a single element using CSS layering?

I have a question about setting a background image for a web page using CSS. Currently, I have the following code: body { font-size: 62.5%; /* Resets 1em to 10px */ font-family: Verdana, Arial, Sans-Serif; background-color: #9D5922; color: #000; margin ...

Choosing the Right Alignment for Your Selection Box

How can I adjust the alignment of the select box to make it inline with the others? I also need to apply this alignment to the three option input boxes. CSS: #newwebsiteSection, #websiteredevelopmentSection, #otherSection{ display:none; } #newwebsite ...

Rendering EJS templates and smoothly scrolling to a specific section on a webpage

I need to display my index page and automatically scroll down to the form section. One way I thought of doing this is by: app.post('/rsvp', (req, res) => { res.render('index/#rsvp', { errors: { email: 'Your email has already ...

Directional Div CSS Transition

Is it feasible to determine the starting direction of a CSS transition? I've designed a div that enlarges in height when hovered over; however, it's situated at the bottom of the page, causing the scrollbar to extend downward. Ideally, I would ...

Angular animation will be triggered when the user clicks using ng-click

In my Angular project, I'm looking to implement an animation that will enlarge the size of an image. Below is the code snippet: <div class="card"> <div class="item images-parent"> <img src="img/carryout-icon.jpg" class="left-image" ...

Find the parent element that houses a particular child element

I am searching for a way to identify all the parent elements that have a certain child element within them. <tr> <i class="myClass"> </i> </tr> For example, I want to find all tr elements that contain an i element with the specif ...

It appears that the pixel sizes are different than what was originally designed

In my project, I have a header panel where the burger button is designed with a width of 32px and height of 24px. .header { display: flex; font-weight: bold; font-size: 50px; height: 100px; border: 1px solid black; position: relativ ...

Display tables based on selected changes with dynamically changing options

My HTML structure displays rows with active and inactive statuses based on a select change, and it's currently functioning correctly. However, the project requirements have changed, allowing for more status options besides just active and inactive. I ...

The error message "ERR_CONNECTION_TIMED_OUT when trying to access Google APIs fonts

Upon deploying my web project on the client server, I encountered an error and noticed slow page loading. GET https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic net::ERR_CONNECTION_TIMED_OUT The browser ...

It's possible for anyone to enhance the appearance of the Download button by adding styles without compromising its functionality

Looking to enhance the style of the Download button as it appears too formal. Seeking assistance in adding some button styles to make it more stylish. The code is correct, just aiming to give the Download button a trendy look with specified styles. ...

Trouble with Chrome's CSS making table cell display as block

After searching, I stumbled upon this question that appeared to have the solution I needed. Surprisingly, even when using chrome 32.0.1700.102, the fiddle provided in the first answer worked perfectly for me. However, when I copied the HTML code into a ne ...

Sometimes I receive a notification that the session ID cannot be regenerated because the session is not active, without any apparent cause

Despite reading numerous posts on this problem, none have provided a solution for me! Some suggest that using session_regenerate_id(true); before session_start(); could be causing the issue. However, this is not applicable to my code. Others recommend remo ...

What steps should we take to ensure that the container beside the fixed left navigation bar is responsive?

Currently, I am working on creating a user interface that features a fixed navigation bar on the left hand side and a responsive content window. Here is what I have implemented so far: <div style="width: 15%; float: left; display: inline;"> <na ...

Issue with transforming rotation in Quirks mode

Currently, I'm developing a website in quirks mode which does not allow the use of . In my project, I am facing an issue where CSS3 translate image is not working in IE10 and 11, although it works fine in IE9 due to the limitations mentioned above. Is ...

A distinctive noise is heard when hovering over multiple instances of a div

I'm trying to implement a feature where a unique sound plays when hovering over a specific div element with a particular class (.trigger). However, I am encountering an issue where multiple instances of this div class result in the same sound being pl ...

Modify the onerror function of the image tag within the onerror function

Here is a way to display images using the img tag: If 1.jpg exists, show 1.jpg. If not, check for 2.jpg and display it if it exists. If neither 1.jpg nor 2.jpg exist, display 3.jpg. <img src="1.jpg" onerror="this.src='2.jpg'; this.oner ...