What could be causing the gap between my hero image and the about section to appear when I adjust the page height?

As I am relatively new to creating responsive CSS, I haven't had much experience yet. When you open the code below in full screen and adjust the tab height, you'll notice that the smaller the height, the larger the gap between my hero and about section becomes. My goal is to maintain a consistent gap size across all devices. Any assistance would be greatly appreciated. Thank you.

/* Your CSS code goes here */
<!DOCTYPE html>
                <html lang="en">

                <head>
                    <meta charset="UTF-8">
                    <meta http-equiv="X-UA-Compatible" content="IE=edge">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <link href="style.css" rel="stylesheet" type="text/css" />
                    <title>Above Photography</title>

                </head>

                <body>

                    <div id="header" class="center">

                        <div id="navBar">

                            <img class="logo" src="./images/AbovePhotographyLogo.png" alt="Logo">

                            <nav>

                                <ul class=n av__links>

                                    <li><a class="page" href="#">Home</a></li>
                                    <li><a class="otherPages" href="#">Photography</a></li>
                                    <li><a class="otherPages" href="#">Videography</a></li>
                                    <li><a class="otherPages" href="#">Contact</a></li>
                                    <a href="#"><button class = "bookNowNav">Book Now</button></a>

                                </ul>

                            </nav>

                        </div>

                        <div id="title">

                            <h1>Above <br>Photography</h1>
                            <h2 id="subTitle">Taking The<br>Perfect Picture</h2>
                            <button class="bookNow">Book Now</button>
                            <button class="learnMore">Learn More</button>

                        </div>

                    </div>

                    <div id="about">

                        <div id="aboutImage"></div>

                        <div id="aboutInfo">

                            <h2 class="">About</h2>

                            <p class="info">Your about information here.</p>

                            <button class="seeWork">Learn More</button>

                        </div>

                    </div>
                    
                </body>
                

Answer №1

As Ouroborus pointed out in the comments, there is no simple solution to this issue for several reasons:

  1. You have set both the header (.center) and the #about divs to position: absolute.

Absolute positioning takes elements out of the normal flow of the document and causes various side effects.

  1. The height of your header is defined as a percentage value without having a parent container with a fixed height. Therefore, it derives its height from the <body>, which also represents the viewport's height. In other words, when the viewport's height changes, so does the height of your #header.

  2. You have specified a fixed margin-top: 860px for the #about section, but since the dimensions of your #header are not fixed (as explained in point 2), this causes issues.

In summary, when the viewport height is reduced to less than 860px, the margin on the about section remains at 860px while the header shrinks accordingly. This results in a larger gap between them. This is how the dynamic works.

It should be noted that if you increase the window's height, the header (being 94% of the body's height) may overlap the about section. *You can test this by applying a background-color to the #header and making the window 1600px tall, for instance. Furthermore, under the current setup, the #title will be vertically centered in the document, potentially causing alignment issues with the content in the header or overlapping with the about section image (or any other content).

My recommendation is:

  • Avoid using position absolute unless absolutely necessary for intricate inner layouts. It is unnecessary for the header container or the about section to be absolute.
  • Before attempting responsive designs, ensure you have a solid grasp of CSS concepts like the box-model, display, and position, as well as flexbox and/or grid layouts (and even floats if you prefer an older approach).

https://www.w3schools.com/css/ is a great starting point for learning more about CSS. Happy coding.

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

Deleting an object with javascript in django: A step-by-step guide

Is there a way to use JavaScript to create a confirmation window before deleting an item? <div class="card-footer"> <a href="{% url 'course_delete' student.slug %}"><button>Delete</button>&l ...

Utilize the grid system from Bootstrap to style HTML div elements

I am working on my angular application and need help with styling items in a Bootstrap grid based on the number of elements in an array. Here's what I'm looking to achieve: If there are 5 items in the array, I want to display the first two items ...

Generating a new dialog box at the exact location of the user's click

I have a canvas element on my website that allows users to select various items. To offer more choices for what can be done with the selected item, I want to create a small popup with a few options. However, I am running into an issue where I cannot positi ...

The left margin is malfunctioning

As a newcomer to css, I am struggling with adding margin-left to my paragraph and <h2>, and it's not taking effect. I have a 700px div and I want to add a 10px margin-left to both <p> and <h2> in relation to the image. Despite my e ...

Using AngularJS to update attributes in an HTML tag within a string

My string contains HTML tags : var str = "<div><p></p><p><i>blabla</i></p><p><i><b>blaaaaaablaaaaa</b></i></p><iframe src='urlAAA' height='400' width=&ap ...

Is it possible to retrieve text from an html document?

I need to scrape a web page that is full of text and save that text into a file. I am currently attempting to use BeautifulSoup, but I'm not sure if it has the capability I need. Here's the situation: The specific text I want to extract is locate ...

python Chromium process leak initiated by requests-html

My program is experiencing a crash due to a memory leak before it can complete the loop. The script I am using: from requests_html import HTMLSession from bs4 import BeautifulSoup import requests for x in range(9376, 23534): session = HTMLSession() ...

Aligning content in the center vertically of a container

My attempt to vertically center some h2 text within a div using display:table-cell along with vertical-align: middle is not successful. The issue seems to be arising because the div I want to center the content in is nested inside another div. Below are ...

Modify the drop-down value based on the selection of a checkbox in HTML

Here is the updated version that I am stuck with. <base href="http://skins4device.com"/> <link rel="stylesheet" href="/gasss/css/ghd.css" type="text/css" media="all"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.m ...

How to transform the bootstrap 4 hamburger icon into a three dots menu icon using css only

The standard bootstrap 4 navigation bar button showcases a classic hamburger icon. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample03" aria-controls="navbarsExample03" aria-expanded="false" aria-label="T ...

Is it possible to use CSS position relative without specifying a relative width?

I am looking for a way to have an element with relative positioning without its child element (using position:absolute) inheriting relative width from the parent. Take for example this scenario: http://jsfiddle.net/t2yJP/. How can I achieve the second bod ...

Can the first row of a flex-box begin in the second column and end in the third column?

Can a layout be created with two rows and three columns without adding any extra elements using the flex property or any other method? .parent{ display:flex; flex-direction:column; } .child1{ background:lightblue; } .child2{ display:flex; border:1px ...

How to Align React Material UI Grid with Varying Row Counts in Each Column

Objective My goal is to design a component that showcases details about a device, including an icon and its current status. For instance: https://i.sstatic.net/UhpnG.png Approach I've Taken I am attempting to accomplish this by structuring a MUI Gr ...

Rgd: Double-Sided Horizontal Slide Control

While browsing the internet, I came across several examples of horizontal sliders with adjustable values. For example, if I set the maximum value as 100 and move the slider 10 sectors to the left, each sector would decrease by 10. What I am trying to ach ...

Is there a way to efficiently retrieve and handle multiple $_POST records in PHP simultaneously?

I am currently working on developing a management interface that allows administrators to make bulk edits to members of a website all at once. While we already have the capability for single edits, there is a need for an option to modify all users simultan ...

Commence the 10-second Redirect Timer

I implemented a page that automatically redirects the user after 10 seconds using the following code snippet. <META HTTP-EQUIV="refresh" CONTENT="10;URL=login.php"> Now, I have this PHP code that I want to display dynamically counting down from 10 ...

Footer that sticks to the bottom of the page across various pages

Having trouble printing a 2-page document on Chrome. The first page has fixed content while the second page has dynamic content in an extended table. The problem I'm facing is keeping the footer at the bottom of the second page. The CSS code below wo ...

Issues arise when attempting to display Sphinx documentation containing SVG images on Internet Explorer 11

I have been working on building Sphinx documentation and incorporating a UML diagram generated as an SVG image using graphviz. The SVG file is embedded in the auto-generated HTML template from Sphinx. While the SVG displays perfectly fine on Chrome and Fi ...

Tips for resolving the issue of encountering the error message "Cannot POST /" while transitioning between different websites

Forgive my lack of knowledge, I'm still in the learning process :) I am attempting to navigate from an HTML website to a React-built website by clicking a button. The first website is a simple HTML page, while the destination website is more complex a ...

Tips for evaluating style modifications on mouseover using cypress

Trying to test hover styles on table rows but encountering issues: Here is the code snippet I am testing: it("Table rows should display correct hover styles", () => { cy.get("table>tbody>tr").each(($el, index, $list) =&g ...