Is there a way to remove the excess white space beneath my content without resorting to using overflow-y: hidden?

I am struggling to eliminate the excess white space below the body of my web page in order to make it fit perfectly within the view of a web browser. Adding height helps with vertical alignment but leaves unwanted white space.

I need a solution that doesn't involve hiding overflow-y, as this interferes with the responsiveness of the code.

Previously, setting the body and HTML to 100% caused issues with vertically aligning the container.

If you visit the page on Github at the following link, you will notice the white space that I'm trying to remove:

Here is a snippet of the key HTML code I've been working with:

<body>...
<header>...</header>
<main>
    <div class="container" id="index">
      <section>
        <h1>Web Designer in London</h1>
        <h2>I create beautiful websites that are easy to use on mobile and desktop.</h2>
        <a href="work.html"><button class="btn-dark">View Work</button></a>
      </section>
    </div>
  </main>
</body>...

Below is some relevant CSS code:

html {
  height: 100%;
}

body {
  font-family: 'Poppins', sans-serif;
  font-size: 18px;
  color: var(--secondary-colour);
  background: linear-gradient(130deg, var(--main-colour) 0%,  var(--main-colour) 20%, #000a18 100%);
  background-image: url('../img/city.svg'), linear-gradient(130deg, var(--main-colour) 0%,  var(--main-colour) 20%, #000a18 100%);
  background-repeat: no-repeat;
  background-position: 50% 100%;
  line-height: 1.7em;
  height: 100%;
  padding: 1em;
  margin: 0;
}

.container {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  align-items: center;
  height: 100%;
  justify-content: center;
}

main {
  height: calc(100% - 2em);
}

The goal is to have no white space visible anywhere on the webpage, but currently there is still unwanted whitespace present.

Answer №1

The default margin of the <ul> element on the linked page is causing the white space by offsetting the <main> element. You have two options to address this issue: remove the default margin from <ul> or adjust the size of your <main>.

ul {
  margin: 0;
}
/* or */
main {
  height: calc(100% - 4em);
}

Answer №2

Perhaps this solution will be effective for your situation.

body {
    height: 100%;
}

Answer №3

Applying a padding to the body along with height:100% will result in the body being 100% height plus the vertical padding.

To ensure that padding is included in the height calculation, you should reset the box-sizing property (usually done on body, or everything via *):

https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing

The box-sizing CSS property determines how the user agent calculates the total width and height of an element.

html {
  height: 100%;
}

body {
  font-family: 'Poppins', sans-serif;
  font-size: 18px;
  color: var(--secondary-colour);
  background: linear-gradient(130deg, var(--main-colour) 0%, var(--main-colour) 20%, #000a18 100%);
  background-image: url('../img/city.svg'), linear-gradient(130deg, var(--main-colour) 0%, var(--main-colour) 20%, #000a18 100%);
  background-repeat: no-repeat;
  background-position: 50% 100%;
  line-height: 1.7em;
  height: 100%;
  padding: 1em;
  margin: 0;
  box-sizing: border-box;  /* !!!!!!!!!!!!  Update !!!!!!!!!!!!!!! */
}

.container {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  align-items: center;
  height: 100%;
  justify-content: center;
}

main {
  height: 100%;  /* !!!!!!!!!!!!  Update !!!!!!!!!!!!!!! */
}


/* show center */
html {
background:linear-gradient(0deg, transparent 50%, rgba(0,0,0,0.2)50%),linear-gradient(90deg, transparent 50%, rgba(0,0,0,0.2)50%);
<main>
  <div class="container" id="index">
    <section>
      <h1>Web Designer in London</h1>
      <h2>I create beautiful websites that are easy to use on mobile and desktop.</h2>
      <a href="work.html"><button class="btn-dark">View Work</button></a>
    </section>
  </div>
</main>

It's important to note that once the box-sizing property includes the padding, there is no longer a need to adjust the height for main.

Answer №4

It seems like my understanding is correct

Please implement the following changes and provide feedback by commenting below

Modification 1

body{
   //delete the padding below
   padding: 1em;
   padding: 1em 1em 0 1em; //include this 
 }

Modification 2

main{
   height: calc(100% - 2em); //also remove this one
 }

Consider adding this as it could potentially resolve the issue

Modification 3

body{
   //only eliminate bottom padding
   padding: 1em 1em 0 1em; //include this 
 }

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 RequiredFieldValidator and RegularExpressionValidator are not functioning properly

I have the following code snippet in one of my "C#" aspx pages. Despite having validation set up, the event attached to cmdPassword still fires even when the textbox is empty. Why are the validations not working? <tr> <td align="left" valign="t ...

Table borders not displaying properly in Chrome when cells are hidden

I'm dealing with a peculiar issue regarding the display of borders in Chrome when individual cells are hidden within an HTML table. The borders disappear, despite being defined for the row and table elements. Does anyone have experience with this spec ...

Filled with information provided on the form page

After completing the form and submitting it, I noticed that when I went back to fill out another request, all the fields were already populated with my previous data. How can I reset the form page to have empty values each time? Appreciate your help ...

Jumping Sticky Table Headers

Looking for a solution to prevent the table header from moving when scrolling through the data: tbody { overflow-y: scroll; } thead, tbody tr { display: table; width: 100%; table-layout: fixed; text-align: left; } thead, th { position: sti ...

Steps for incorporating an icon into a datagrid in ReactJS

I'm looking to enhance my datagrid by incorporating icons in a specific column, particularly the 'Role' column. However, I'm unsure of the feasibility and implementation process within a datagrid. Despite scouring the web for solutions, ...

Angular template src variable issue with no solution in sight

The videoSrc variable is not evaluating correctly images/{{videoSrc}}.mp4 When I write just videoSrc, it works fine. But when I concatenate it with other strings, it doesn't work. Check out this jsfiddle ...

Looking for assistance in designing a responsive web page with CSS, specifically in determining the optimal page width

Currently, I am working on making my web page responsive for four different screen sizes (320px, 640px, 980px, and 1024px). Everything looks great and adapts well when I resize the site up to 1024px. However, once the size goes beyond that, I want to preve ...

Using SASS variables in JavaScript: A guide

My JavaScript file contains a list of color variables as an Object. export const colors = [ { colorVariable: "$ui-background" }, { colorVariable: "$ui-01" }, { colorVariable: "$ui-02" }, ... ] The Object above is derived from a scss file whic ...

Retrieve the site's title content using PHP

I created a code to scrape website content from platforms like Facebook and Google+. $html = file_get_contents_curl($url); if ($html) { //parsing begins here: $doc = new DOMDocument(); @$doc->loadHTML($html); $nodes = $doc ...

chaotic telerik editor arrangement

I have incorporated the Rad Editor into my ASP.NET page. <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <telerik:RadEditor ID="reSummery" runat="server" > </telerik:RadEditor> Despite not referencing ...

jQuery automatic slider for seamless transitions

I am in need of assistance with the coding for a website I'm currently constructing at www.diveintodesign.co.uk/ChrisMcCrone/index.html The coding being used is sourced from http://jquery.malsup.com/cycle/ The central large image functions as a slid ...

Creating a seamless and interactive online platform

I am in the process of designing a website that has a sleek and dynamic layout, rather than just a static homepage. Let me explain further: Here is my current setup so you can understand what I am trying to achieve. By dynamic, I mean that when the page ...

Angular not updating the values in real time

First and foremost, I am utilizing socket.io to emit data. Data is emitted upon connection (so the website does not appear blank) as well as when certain events occur. Upon initial connection or page refresh, everything updates and functions smoothly. Howe ...

How to create a floating <Toolbar/> with ReactJS, Redux, and Material-UI

Can anyone help me figure out how to make a toolbar floatable when scrolling down using Material-UI? I tried setting textAlign:'center', position: 'fixed', top: 0, but it's resizing strangely when applied to the <Toolbar/>. ...

Exploring different options for parsing HTML content and extracting text from strings that do not contain HTML/XML tags

When looking at this particular solution for stripping HTML tags from a string, the process involves passing the string to rvest::read_html() in order to generate an html_document object. Subsequently, this object is input into rvest::html_text() to obtai ...

Padding causing links to break exclusively in Firefox

As a seasoned front-end developer, I recently encountered an issue that has stumped me. My main navigation bar has extensive right padding to ensure the hover dropdowns have ample space. The problem seems to be in this piece of code: HTML: <div id="h ...

Tips for organizing labels and user input within an HTML document

I attempted to align inputs and labels horizontally. Here is what I tried: <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="row"> <div class="span2"> <h2& ...

I possess a solitary div element that requires dynamic replication

I have a single container and an unspecified number of rows of data. I want to display this data on HTML cards that are generated dynamically based on the number of rows. For example, if there are 10 rows of data, I need to create 10 card elements with ea ...

Is there a way to differentiate the color of an active link from an inactive one, so users can easily identify which link they are currently viewing?

How can I customize the color of text for the active page on my website's sidebar? For example, I have two hyperlinks, one for HOME and one for ABOUT. When a user clicks on the HOME link, I want the text color to change to green while the ABOUT link r ...

Ways to configure a select-multiple element to send data as an array

I am experiencing an issue with a form I have set up. Here is the current code: <form method="post" action="action.php"> <select id='select' multiple='multiple'> <option value="1"> Option1 <option> ...