Building websites using HTML,CSS, and Angular 7 for implementing header, content, and footer design

Just starting out with HTML, CSS, and Angular here!

I'm attempting to build an Angular app with three main divs on the screen: 1. header 2. content 3. footer

The goal is to have a fixed page that cannot be scrolled. The header and footer should always stay at the top and bottom, respectively. The middle section (content) should be scrollable only. No overlapping of content by the header or footer. Responsive design that works across different devices and screens.

Check out this fiddle for an example, although it currently has content overlap:

JS Fiddle

I managed to achieve this layout with a fixed screen size but struggle with different sizes.

Here's another snippet of my code...

html {
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100%;
}
<body>
  <app-root class="h-100 w-100 align-items-center"></app-root>
</body>

.headerdiv {
  margin-top: 0px;
  height: 60px;
  min-height: 60px;
}

.contentdiv {
  position: relative;
  overflow: scroll;
  min-height: 91%;
}

.footerdiv {
  position: relative;
  overflow: hidden;
  margin-bottom: 0px;
  padding-bottom: 0px;
  height: 20px;
  min-height: 20px;
  width: 100%;
  background-color: darkblue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div class="headerdiv">
  <app-hsbc-header-bar></app-hsbc-header-bar>
</div>

<div class="contentdiv">
  <div>
    <router-outlet></router-outlet>
  </div>
</div>
<footer class="footerdiv">
  <app-application-footer></app-application-footer>
</footer>

Looking for some assistance on this! Thanks in advance.

Answer №1

To ensure the main content div has a dynamic height, you can use the following pattern:

height: calc(100vh - (headerHeight + footerHeight))

This allows the height to scale with the view height of the browser. Additionally, add overflow-y:auto so that when the content exceeds the height, it becomes scrollable:

nav{
 height:20vh;
 /* You can also use fixed pixel units */
 background-color: green;
}
footer{
 height:20vh;
 /* Or fixed pixel units */
 background-color: black;
}
section {
  height: 60vh;
  /* - Height: 100vh - (navheight + footer)
     - Overflow-y makes the section scrollable 
  when it exceeds the fixed height */
  overflow-y: auto;
  transition: all 0.5s;
  background-color: yellow;
}
<nav></nav>
<section>
 The main content will be scrollable if it exceeds the fixed height.
</section>
<footer></footer>

Answer №2

If you're looking for a stylish navigation solution, consider checking out the Bootstrap Navbar. It comes with all the essential CSS styles you need.

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

The Angular 2 view appears on the screen before the data finishes loading in the ngOnInit

Utilizing the github API in my angular 2 application, I encounter an issue where the view renders before ngOnInit has finished loading data. This leads to a Cannot read property of undefined error. The relevant portion of my code is as follows: ngOnInit() ...

Creating a radial gradient effect using JavaScript

I've been experimenting with setting a radial gradient as the background of a div using JavaScript. My goal is to have the gradient start in the middle with around 0.8 opacity, gradually fading to 0 towards the edges to create a soft fading effect. I& ...

What is the most effective method for enhancing the performance of HTML tags by utilizing multiple classes? Angular 2

I'm currently working on developing a price-centric calendar structure, which consists of three nested elements: - calendar-layout -- calendar-month --- calendar-week Within the calendar-week element, I am tasked with performing various calculations ...

When trying to implement a dark/light theme, CSS variables may not function properly on the body tag

Currently, I am in the process of developing two themes (light and dark) for my React website. I have defined color variables for each theme in the main CSS file as shown below: #light{ --color-bg: #4e4f50; --color-bg-variant: #746c70; --color-primary: #e2 ...

Utilizing Cookies in PHP to keep track of site visits

I'm a newbie to PHP and struggling with using Cookies! My goal is to create a cookie that tracks the number of times a page is loaded within a one-minute lifetime. Once the minute is up, the cookie should be unset and the counter reset to 0. Here&apo ...

The height of EasyAutoComplete is restricted by the designated div height

I am experiencing an issue with my EasyAutoComplete feature that displays City & PostalCode information. The problem lies in the height of the div containing the input field, which limits the visibility of the EasyAutocomplete window. Only the first elemen ...

Dynamically assigning column values based on object properties

I am currently utilizing the Ionic Framework along with its grid system that is reminiscent of Bootstrap. However, I believe my query leans more towards AngularJS than specific Ionic components. Here is what I have: <ion-col *ngFor="let col of row ...

Tips for including a background image using the :after pseudo-element in Angular 2

I'm facing a challenge with passing a URL image from my HTML to my CSS in Angular, and I can't seem to figure it out: Here is a snippet of my CSS: card-profile_visual { height: $visual-height; overflow: hidden; position: relat ...

What is preventing the ":last-child" selector from working when the parent element is <body>?

Here is a basic HTML structure: <body> <a> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </a> </body> The divs are nested within ...

Angular2/Typescript: Transforming a Javascript/Typescript Date into a C# DateTime string on the client side

Currently immersed in an Angular2/Typescript project, I am faced with the task of sending a date to a C# backend. Despite my extensive research, all I could uncover through Google searches was information on converting the date on the backend side. My la ...

Implementing PHP logic for adding a class to an HTML tag

I have a PHP file that handles the sending of my form. Everything is functioning correctly, but I need to make a small modification. When the message is successfully sent, I want PHP to dynamically add the "active" class to a specific div in my HTML. This ...

Alignment of headline remains off-center despite having the text-center attribute

I'm currently developing a school project website and I'm facing an issue with centering my headlines. Specifically, I can't seem to figure out how to center my h1. Everything else is working fine except for that particular headline. I&apo ...

Develop unique web components and distribute them across various frameworks

Currently, I am working on two projects that utilize Angular and React. I have noticed that certain components are duplicated in both projects. To streamline this process, I am considering creating a company library where I can develop custom components on ...

What is the best method for releasing an NX library along with all its bundled dependencies?

This problem is quite common in GitHub's NX repository, but I have not been able to find a solution there. Within my workspace, I have two buildable libraries: ui/avatar and ui/icon, as well as a publishable library named bar The goal is to utilize ...

changes in size in relation to the position of the parent element

Utilizing the transition:scale(1.2) property to conceal a div positioned in the lower left corner of the viewport. Currently, the scaling effect originates from the center as intended: View 'CURRENTLY' on Fiddle I aim to scale it as if the div ...

Tips for consolidating rows with identical data using the R package GT

I have a dataset containing unique identifiers, summary statistics, and individualized comments. The structure of the table is as follows: Name Mean Median Comment Boat 7 5 Can float. Boat 7 5 Has been known to ...

Looking for a Regular Expression Validation Pattern!

Is there anyone who can provide insight into how to establish this validation pattern? All sentences must start with a capital letter, and the message should conclude with a full stop. There should be no spelling errors. ...

What is the best way to soften the background image without losing its sharp edges?

Take a look at the desired effect in my mockup. I have successfully masked an image to a button within my form However, when I apply a blur to the background-image, the edges of my button become too soft, which is not what I want. Is there a way to keep ...

What's the best way to restrict characters in a paragraph?

I am working on an Angular application and I need to restrict the number of characters in a paragraph (p) to 50, after which it should break to a new line. Here is the template I am using: <section class="echeq-element-html-display border-box" [ng ...

[innerText]: Text containing opening angle bracket

Can anyone explain why Angular [innerHtml] is removing text that comes after the left angle bracket? I encountered an issue with a line of HTML content, like so: text1 <text2 <a>link</a> Instead of displaying the content as is, it shows: ...