Unusual gap of white space found between the html tag and body section

My goal is to achieve a full-screen image background with a scrollable div in the center. Here is the code I came up with:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bio</title>
<link href="../css/layout-base.css" rel="stylesheet">
<script type="text/javascript" src="../jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(window).ready(function(){
        var background = $('#background');
        var scrollable = $('#scrollable-container');
        var halfWhite = $('#halfWhite');
        var halfBlack = $('#halfBlack');
        /* calculate window size */
        var maxWidth = $(window).width();
        var maxHeight = $(window).height();

        /* set background image dimensions */
        background.css("height",maxHeight);
        background.css("width",maxWidth);

        scrollable.css("height",maxHeight);

        /* set padding background dimensions */
        halfWhite.css("height",maxHeight);
        halfWhite.css("width",maxWidth/2);
        halfBlack.css("height",maxHeight);
        halfBlack.css("width",maxWidth/2);
});
</script>
</head>
<body>
<div id="background">
    <div id="halfWhite"></div>
    <div id="halfBlack"></div>
    <div id="scrollable-container">
        <div class="content">
            <a href="#" class="menu" id="home" target="_self"><img src="../media/index/bio1.png"/></a>
            <a href="#" class="menu" id="events" target="_self"><img src="../media/index/events2.png"/></a>
            <a href="#" class="menu" id="gallery" target="_self"><img src="../media/index/gallery3.png"/></a>
            <a href="#" class="menu" id="disco" target="_self"><img src="../media/index/disco4.png"/></a>
        </div><!--div content -->
    </div>
</div><!-- div background -->
</body>
</html>

Including the relevant css:

body{
overflow:hidden;
margin:0!important;
}
#background{
background-image:url(../media/index/back.png);
background-size:contain;
background-position:center;
background-repeat:no-repeat;
}
#halfWhite{
position:relative;
background-color: white;
z-index: -10;
float: left;
}
#halfBlack{
position:relative;
background-color: black;
z-index: -10;
float: right;
}
#scrollable-container{margin-left: 15%;margin-right: 15%;background-color:rgba(0,0,0,0.00)}
.content{
margin-top:1%;
height:100%;
position: relative;
padding-left: 5%;
padding-right: 5%;
box-shadow: -10px 2px 15px #dedede,10px -2px  15px #dedede;
-moz-box-shadow:-10px 2px 15px #dedede,10px -2px  15px #dedede;
-webkit-box-shadow:-10px 2px 15px #dedede,10px -2px  15px #dedede;
background-color:rgba(255,255,255,0.8);
}
.menu{width:15%}
.menu img{width:100%}
#home{position:absolute;top:0px;left:0px;}
#events{position:absolute;top:0px;right:0px;}
#gallery{position:absolute;bottom:0px;left:0px;}
#disco{position:absolute;bottom:0px;right:0px;}

Although the result looks promising, I have noticed an unusual white space between the html and body tags. How can I troubleshoot this issue? Could it be caused by something specific? As a beginner in web development, I am unsure if my approach is correct. Any advice or tips would be greatly appreciated.

Answer №1

The issue with margins that I mentioned in my previous comments appears to be related to collapsing margins

http://www.w3.org/TR/CSS2/box.html#collapsing-margins

To address this, consider removing the top margin from .content and adding padding-top to the container #scrollable-container

It's possible that this solution aligns with what you're attempting to achieve

Answer №2

The issue lies in the 1% margin-top set on .content (located on Line 26 of the layout-base.css file)

Margins have a tendency to extend beyond their containing elements.

Answer №3

#background {
padding:0;
background-image:url(../media/index/back.png);
background-size:cover;
background-position:center;
background-repeat:no-repeat;
}

In case the above code is not effective, consider removing margin-top:1%; and setting it to zero in the .content section.

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

Uninitialized NodeJS environment variables

I'm having trouble setting up environment variables. After creating the file and running the server, they appear to be undefined. I am using nodemon and have already tried restarting my server without success. UPDATED .env MONGO_ATLAS_PW = "xxxx"; ...

Html Agility Toolkit - Eliminating an element without affecting its inner content

Removing the element can be done easily using note.Remove() like this: HtmlDocument html = new HtmlDocument(); html.Load(Server.MapPath(@"~\Site\themes\default\index.cshtml")); foreach (var item in html.DocumentNode.SelectNodes("//re ...

Access an HTML element and using JavaScript to make changes to it

As a new web developer, I am eager to create a grid of file upload zones on my site. I have decided to use DropZone.js for this project. I have customized DropZone and added multiple drop zones in the HTML. The grid layout consists of four rows with four ...

I am currently facing difficulty in retrieving the selected value from a jQuery dropdown menu

I have a project that involves currency conversion, where I need the input value and selected dropdown value to update dynamically on the same page. There are two input tags and two select dropdown tags for this purpose. $(document).ready(function () { ...

Why is the margin of a div not factored into the calculation when it

Currently, I am focusing on practicing basic CSS. My goal is to achieve a specific layout for the header of a webpage that resembles this image with a wide top margin: wide top margin. Here is the HTML code I am working with: <div class="heade ...

Display the HTML content once the work with AJAX and jQuery has been successfully finished

Below are the codes that I have created to illustrate my question. It's not a complete set of code, just enough to explain my query. The process goes like this: HTML loads -> calls ajax -> gets JSON response -> appends table row with the JSO ...

What is the process for defining custom properties for RequestHandler in Express.js middleware functions?

In my express application, I have implemented an error handling middleware that handles errors as follows: export const errorMiddleware = (app: Application): void => { // If the route is not correct app.use(((req, res, next): void => { const ...

Tips for transferring a JavaScript object to a Node.js server

I must admit, I am positive that the solution to my issue is incredibly simple yet it has been evading me for more than a week now and causing me endless frustration. My current project involves creating a web app for quoting purposes within my workplace, ...

Appending a new element to a JSON object using JavaScript

Hey there, I have a JSON object called departments. When I use console.log(departments) it displays the following data: { _id: 58089a9c86337d1894ae1834, departmentName: 'Software Engineering', clientId: '57ff553e94542e1c2fd41d26', ...

Tips for retaining CSS modifications applied with jQuery following an AJAX or form submission

Attempting to conceal specific payment options on our Lightspeed Ecommerce website using jQuery within a designated timeframe (from 18:00 to 24:00) solely for residents in the Netherlands. Due to the inability to modify the checkout page file directly, I ...

Overflow issues arise when incorporating an embedded iframe (YouTube) into a Bootstrap website, hindering the visibility of surrounding

So, I have a youtube video embedded on my page and when I resize the page, the video frame doesn't adjust responsively like the rest of the content. It overflows and blocks other site content. I'm looking to make it responsive if possible or at ...

One div takes a backseat to the other div

I recently delved into learning Bootstrap, but I'm baffled as to why one div is appearing behind another. <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Fa ...

Using media queries in JavaScript

I've been trying to figure out how to format these parameters: @media screen and (-webkit-min-device-pixel-ratio: 1.3), (min-resolution: 124.8dpi), (max-device-width: 550px) My goal is to create an if statement using the values above, structured lik ...

Executing search bar capability through the use of AJAX and HTTP requests in JavaScript

I am currently working on implementing a search feature that will locate data based on the user's query. Specifically, I want to create a search bar in my HTML that can search for book titles stored in my database accessible through GET requests. Alth ...

Tips on how to stop a webpage from scrolling and instead allow only the inner content to scroll

Check out my plunker for reference. The goal I am aiming for is as follows: The webpage should stay fixed and not scroll in any direction If the content overflows its container, a scroll bar should appear strictly within that container I have a main co ...

Retrieve the data stored within hidden input fields in a form

Is it possible for jQuery to access the values of hidden inputs within a hidden element, such as a form or div? Could this behavior be caused by the browser? In my case, I have a tabbed view with two tabs - one for image editing and the other for image in ...

In a Django template, code written inside the <script> tag fails to execute

I'm currently integrating Bootstrap File Input into my Django application. All required files have been loaded in the header section. Below is the form I am using: <form enctype="multipart/form-data"> <div> <input id="file1" name="fi ...

Deciphering unknown data for tabling using AJAX and jQuery

I am currently utilizing an API to retrieve a response. Within the ajax success function, I receive a response structured like this: { "Capabilities": { "System": { "SystemLogging": "true", "SystemBackup": "true", ... "DHCPv6 ...

creating hidden and displayed forms using php

I am in need of a hidden form that only becomes visible after the user clicks a button. Once the submit button is pressed, the form should return to its invisible state. Does anyone have any suggestions on how to achieve this functionality? I believe it m ...

The error message "require is not defined in React.js" indicates that the required dependency is

As I delve into React coding, the following lines are a part of my code: var React = require('react'); For setting up React, I referred to tutorialspoint. The installation directory is set to /Desktop/reactApp/. My React code is executed from ...