Tips for positioning a div element within the body of a webpage to maintain a predetermined height and width

Currently, I am developing a single-page application using AngularJS. I have specific routes in mind where I want to introduce new HTML templates.
To accomplish this, I have created a container labeled with the ID #main positioned between two navbars (header and footer). Additionally, there is an image background included in a separate div located above all other HTML elements within the body tag.

The structure of my page looks like this:

<body ng-controller="mainController">
  <div id="background"></div>
  <div id="navbar-override" ...> ... </div>

  <div id="main" ng-view></div>

  <div id="navbar-bottom-override" ...> ... </div>
</body>

My question now is: How can I ensure that the #main div always maintains the same height and width (full available h&w) across the entire page? Here is an illustration depicting how the #main div should interact with the rest of the content on the page.

P.S.: Below is the CSS for the html tag:

html {
  height: 100%;
  width: 100%;
  padding: 65px;
}

Answer №1

To ensure that your #main div stretches to the width of the screen (taking into account the 65px padding on each side from the html), consider removing the padding and adding it as margin to the #main for a full header and footer stretch effect. If you also want to set the height of #main to match the screen height while accounting for 50px tall headers and footers:

#main {
  height: calc(100vw - 100px);
  padding-left: 65px;
  padding-right: 65px;
}

Answer №2

To create a custom style for your main section, you'll need to include the following CSS:

#main{
   width: ---custom-width---;
   height: ---custom-height---;
   display:block;
}

Additionally, you should consider handling overflow content. Learn more about it here: http://www.w3schools.com/cssref/pr_pos_overflow.asp

You can also take advantage of CSS calculations for dimensions:

height: calc( 100% - 100px );

In this example, 100px represents the combined height of your header and footer.

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

Maximizing Efficiency with Repeater and jQuery Integration

After searching through various blog answers and trying different solutions, I am still facing errors that are not getting resolved. It seems like none of the fixes are working for my problem. $("#<%=plusBttn.ClientID%>") The specific error message ...

The information is not being stored in Excel despite the fact that the Excel document has been generated with a header

I have been working on a project that involves fetching book details from the Google Books API and using generative AI to create descriptions for them. I have successfully created an Excel file, but I am facing an issue with saving data inside it. It' ...

What could be causing the mousewheel event in my code to remain active?

Whenever I try to scroll on Google Chrome, an error occurs on my website. jquery-3.3.1.min.js:2 [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See To resolve this issue: $(document).ready(f ...

The jQuery dynamic fields vanish mysteriously after being validated

I am facing an issue with my jQuery and validation. Below is the code snippet causing the problem: var fielddd = 1; $(document).on('click', '.btn.add-field', function() { fielddd++; $('#newfield').append('< ...

Calculating the number of items in the Ajax response list

Using jQuery to Count List Items $.ajax({ url : "/assets/inc/list.php", success : function (data) { console.log($(data).filter('li').size()); } }); By implementing the above code, I attempted to calculate the total number of ...

Issue with rendering <li> elements in Firefox browser detected

I have been working on a website and encountered an issue with the display of list elements in Firefox. The list is not showing consistently in Firefox, but it appears fine in IE, Opera, and Safari. I have attached an image below showing the difference bet ...

How can I implement a scroll functionality to navigate to the next item in a Vuetify v-carousel?

I'm currently working on a front page layout using the v-carousel component and I am looking to achieve automatic scrolling to the next item without the need for arrows or delimiters. How can I make this happen? Below is my current code: <template ...

Refreshing web pages using AJAX

I currently have an application that includes a search feature where users can look up items in the database. The search functionality is working well with AJAX, but I'm now looking to incorporate this AJAX functionality into my pagination system. Spe ...

Determining the Existence of Duplicates in an HTML Table with Multiple Inputs Using JavaScript

After spending countless hours on research with no luck, I've finally come to seek assistance from you. In my form, I have an input field and a select field, along with a table generated using PHP from my database that displays team names and their r ...

Using jQuery to save PHP form output into an Excel spreadsheet

I have a PHP-enabled form on my website for collecting Address details. Currently, the output is sent to my email inbox. However, I would like the output data to be saved in an external Excel file named "address.xls" using jQuery/JSON. The input fields of ...

Convert HTML Form to PDF or Docx with Angular 4

My current setup involves Angular 4 with Node and MySQL. I have a form that, upon submission, needs to trigger a Save As... dialog box for the user to save the entered form contents as either a PDF or Word Doc. I've attempted using htmlDox and saveAs ...

Struggling to perform a basic http GET request in Angular 2

Attempting to create a basic http GET request in my Angular2 app: this.http.get("https://mybaseurl.com/hello") .map(res => res.json()) .subscribe( function(response) { console.log("Success Response" + response)}, function(error) { conso ...

Submitting a form without uploading a file in Spring MVC: A step-by-step guide

When working with a form that includes input text fields and an input file field for database entries, I encountered an issue when creating a second form to edit the same entry. The data was retrieved from the database and filled into the new form, mirrori ...

Guide on assigning a material to ColladaLoader or OBJLoader

I've searched extensively through the documentation and numerous examples, but I couldn't find the correct syntax for assigning a material to either a Collada .dae or OBJLoader .obj file. Json files seem to work well when creating a Mesh, with t ...

connect input field with dropdown menu

Check out my Demo. I am looking to link a text box with a select list, so when I type "vahid" in the textbox, the value changes to vahid in the select list. $scope.options2 = [{ name: 'omid', value: 'something-about-ali' }, ...

Guide on how to have two controllers execute identical tasks in Angular while modifying the appearance of the website

Trying to recreate Google's homepage functionality using Angular has been challenging for me. Despite watching Egghead videos and studying the API extensively, I couldn't find a specific example for this behavior. Here's what I aim to achiev ...

I tried running the sample program from the website in mongoose, but I encountered a persistent error: "TypeError: fluffy.speak is not a function."

const mongoose = require('mongoose'); main().catch(err => console.log(err)); async function main() { await mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true }); console.log("Connection successfu ...

What is the best way to ensure the active tab remains visible?

I am using the bs-admin-bcore Bootstrap theme and I am looking to enhance the dynamic functionality of the menu in the "menu.php" file. Here is an example of the current code: <ul id="menu" class="collapse"> <li class="panel"> < ...

Utilizing Conditional Logic to Create a Dynamic Menu

I have a navigation menu on my website that is divided into two sections. There is a left panel and a right panel which slide in from the side when their respective buttons are clicked, covering the browser window. The functionality of sliding in the pan ...

jQuery has a problem with the $.each method

I've created a function that checks elements with the class name .sitem. If any of these elements have a blank value, it should return an error message. Otherwise, the code should proceed as normal. if($(".sitem").each(function(ss, element) { if($(t ...