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

How can I use jQuery to activate and deactivate a class in HTML?

My jQuery function for handling tabs is as follows: jQuery(document).ready(function($) { tab = $('.tabs h3 a'); tab.on('click', function(event) { event.preventDefault(); tab.removeClass('active'); ...

Unordered list not floating properly - successful in JSFiddle but not displaying correctly in web browser despite updating Chrome and Firefox

Having trouble floating an unordered list? Check out this jfiddle example that aligns a list next to some text: Here is the updated jfiddle link: https://jsfiddle.net/8qzygaog/ I created a test document based on the example, but it's not working as ...

Tips for avoiding the initial rendering of react components on a page when styled-components are not yet loaded

I have developed a unique custom component library using React and styled-components for creating reusable components. I then imported this library into my nextJS project, but I noticed that the styles from the custom component library are not applied duri ...

Tips for incorporating a value within the AngularJS select function

Having an issue with passing a list value in the html select method using AngularJS. Here is my code: app.js $scope.subcategory = function() { var query = "SELECT unit FROM Length;"; $cordovaSQLite.execute(db, query).then(function(res) { ...

Using regular expressions in JavaScript, how can one extract the content along with the HTML tags from within the tags?

Below is the text to be analyzed: how much production in batu The text is displayed with HTML tags where each word is wrapped in a span with a specific style or class. For example: '<span style="">how &nbsp;</span><span style ...

Strategies for maintaining login status in Selenium

When utilizing selenium and bs4 to parse a webpage, I encounter an issue where the webpage requires scanning a QR code and entering a verification code to log in. To address this, I have implemented the use of WebDriverWait to pause the script until the u ...

Creating a JSFiddle with sprites using source and image files from Github with THREE.JS - a step-by-step guide

Greetings! I am currently working on creating a JSFiddle based on the official THREE.js HUD Sprites example. However, I am facing an issue where the sprite images do not seem to load or apply using the URLs specified in the original file:- //... URL' ...

Height of CSS border-top

I'm facing an issue with setting the height of my top border. It seems like a traditional solution is not possible based on what I have read so far. However, I am determined to find a workaround for this problem. My goal is to have the border align at ...

Eliminating quotation marks from individual elements within a JavaScript array that includes JSON-encoded HTML strings retrieved from a MySQL database using PHP

Performing an Ajax call to fetch data from a MySQL database using the data1.php file with PDO results in HTML strings being stored in an array, encoded into JSON format, and then sent to the Ajax response function for display on a webpage. However, dealing ...

What is the best way to upload a file without finalizing the form submission?

I have been working on a task to upload a file using ajax and php without refreshing the page when submitting. My code seems to be functioning well and alerts a valid message when I use the preg_match function. However, when I include the rest of the valid ...

Issue with AngularJS causing HTML input field to limit the display to only three digits

Whenever I input a number with 4 digits or more (excluding decimals) into the designated box, it mysteriously disappears once I click away (blur). Could it be due to the currency filter causing this issue? Even though the model retains the value when logg ...

Transforming the MVC model attribute into an HTML attribute

Is there a way to include model attributes in the HTML input tag? Code [Required] [StringLength(20)] public string Username { get; set; } [Required] [StringLength(20)] [DataType(DataType.Password)] public string Password { get; set; } Expected Output: ...

Removing div elements containing specific text using jQuery

Hello everyone, I am trying to remove all divs that contain a specific part of a string. Does anyone know how I can do this? This is what my original HTML looks like: <div class="article-options_4"></div> And this is the new HTML structure, ...

Retrieve the value of the second child element in a table cell when clicking on it with Javascript

I have created a table with one row that includes the title of the month and a cell containing an inner table with multiple rows and cells. I want to display the content of the second cell in the second table as a modal box or alert dialog when it is click ...

Is there a way to seamlessly transition the visibility of the Bootstrap 5.3 Spinner as it loads and unloads?

After delving into some research regarding Bootstrap-compatible spinners, I stumbled upon a piece of code. Take a look: function getData() { var spinner = document.getElementById("spinner"); spinner.style.display ...

Tips for customizing scroll bar padding and margin using CSS classes or IDs

I am looking to customize three different types of scrollbars with unique padding and margins. Here is the global style for my scrollbars: /* Modifying the scroll bar across the whole application */ /* width */ ::-webkit-scrollbar { width: 5px; he ...

Is there a way to transfer a significant volume of data from one webpage to another without relying on the POST

Currently, I am utilizing a web server framework that exclusively operates with GET requests. Presently, my task involves transferring a substantial volume of data (specifically the text content in a textarea) inputted by users onto another page where it i ...

How can I design a side navigation menu using Bootstrap?

I've come across various tutorials online on how to create a side collapsible menu, but they all involve a lot of code. I just need to toggle the visibility of a specific div within this structure: <div class="row"> <div class="col-md-2" ...

My JavaScript/Jquery functions are not running as expected

I need some help creating a simple image rotation feature. I have a folder named comics where the images are stored locally with names like comic_(number). However, when I click my buttons, nothing happens. The previous button doesn't even get disable ...

Importing a .js file into HTML with AJAX

The following JavaScript code is located within index.html between "<script type="text/javascript">" function callanular() { peticion_http = new XMLHttpRequest(); peticion_http.onreadystatechange = showContent; peticion_ht ...