What causes sections that are the same to have varying heights?

My layout consists of 4 sections, each with an aside and main taking up half the screen. The first section's aside starts on the left, then moves to the right for the second, alternating each section. I have copied the HTML of the first section for the rest. By using flex property "order" to switch the positions of aside/main containers, all CSS is being uniformly applied across the sections. However, when I utilize jQuery's height() method, the height of the first main section measures at 1252px while the next three are 1216px. What could be causing the initial section to be taller than the subsequent ones?

Pen: https://codepen.io/marti2221/pen/QgXoMr

// JavaScript functions for changing position properties
            
   // two functions, one changes to fixed 
    
    var windw = this;
    
    
    $.fn.startFixed = function ( pos ) {
        var $this = this,
            $window = $(windw);
        
        $window.scroll(function(e){
            if ($window.scrollTop() > pos) {
                $this.css({
                    position: 'fixed',
                    top: pos
                });
            } else {
                $this.css({
                    position: 'absolute',
                    top: pos + 200
                });
            }
        });
    };
    
    
    
    // This function changes to absolute
    
    $.fn.followTo = function ( pos ) {
        var $this = this,
            $window = $(windw);
        
        $window.scroll(function(e){
            if ($window.scrollTop() > pos) {
                $this.css({
                    position: 'absolute',
                    top: pos
                });
            } else {
                $this.css({
                    position: 'fixed',
                    top: 0
                });
            }
        });
    };
    
    // Setting values for start/stop points
    
    var asideHeight = $(".aside").height();
    var stopPoint = asideHeight - 303; 
    
    var viewPortHeight = $(window).height();
    
    $('.container-text').followTo(stopPoint);
     
    // Variables returning undefined in console
    
    var firstPos = $(".container-text").position();
    var firstPosAt = $(".container-text").css('position');
    
    var secondPos = $("#section2").position();
    var secondPosAt = $("#section2").css("position");
    
    var thirdPos = $("#section3").position();
    var thirdPosAt = $("#section3").css("position");
    
    var lastPos = $("#lastFixed").position();
    var lastPosAt = $("#lastFixed").css('position');
    
    var secHeight = $("#main2").height();
    var secHeight1 = $(".main").height();
    
    // Outputting heights of main sections
    
    console.log(secHeight1); //first section height = 1252
    
    console.log(secHeight); // second and following 2 = 1216... why?
    
    console.log(firstPos);
    console.log(firstPosAt);
    console.log(secondPos); 
    console.log(secondPosAt); 
    console.log(thirdPos); 
    console.log(thirdPosAt); 
    console.log(lastPos); 
    console.log(lastPosAt);   
           

Answer №1

The discrepancy arises from an additional line of text within the <article> tag under the 'Second heading' section of the initial .container-content.

The content of the article within the first .container-content is as follows:

<article>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse pharetra enim sagittis velit iaculis, a consectetur nisi sagittis. Etiam sagittis enim sapien, in ultricies nibh maximus quis. Nulla facilisi. Ut mattis gravida semper. Nam nec lacinia nulla. Proin euismod dolor lacus, id sagittis sem viverra accumsan. Curabitur eros est, vehicula vel nibh eget, gravida porttitor turpis. Vivamus a sollicitudin nisl. Etiam sagittis enim sapien, in Nulla facilisi. Etiam sagittis enim sapien, in ultricies nibh maximus quis. Nulla facilisi.
</article>

This includes the addition of

Etiam sagittis enim sapien, in Nulla facilisi. Etiam sagittis enim sapien, in ultricies nibh maximus quis. Nulla facilisi.
at the end.

All other article elements contain only:

<article>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse pharetra enim sagittis velit iaculis, a consectetur nisi sagittis. Etiam sagittis enim sapien, in ultricies nibh maximus quis. Nulla facilisi. Ut mattis gravida semper. Nam nec lacinia nulla. Proin euismod dolor lacus, id sagittis sem viverra accumsan. Curabitur eros est, vehicula vel nibh eget, gravida porttitor turpis. Vivamus a sollicitudin nisl.
</article>

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 footer is anchored at the bottom on one page but mysteriously relocates to the center on the next page

I've been working on creating a footer for my Angular application and here's the code for it: // HTML <footer class="footer"> // code for footer </footer> // LESS .footer { position: absolute; bottom: 0; width: 100% ...

Detailed enrollment procedure

I am facing an issue with the code in my HTML that validates input types. The system detects empty fields and prevents proceeding to the next step. How can I disable this validation as some of the fields are not required? For instance, the input type < ...

Displaying a DIV after entering text into an <input> field using JavaScript

Attempting to create a JavaScript function that will show/hide a 'DIV' after entering some text into an input field. I have successfully written the function, but I am struggling to make it only work when the user enters a value greater than 8. ...

Updating the DOM after scrolling using jQuery

jQuery hover functionality is not working correctly after scrolling. $(document).ready(function() { $('img').hover(function(){ alert('hello'); },function(){ alert('hello not'); }); }); When hoveri ...

Conceal the div until the animation with a delay of `1s` has finished, then reveal it afterwards

I have incorporated a CSS file to introduce animations on the website I am currently developing. You can find it here: The premise of this CSS file is straightforward - by adding specific class names to div elements, you can animate them as you scroll up ...

Troubleshooting ASP.NET MVC 4 Clientside Validation Failure

I am encountering an issue with implementing custom attribute client-side logic in Visual Studio 2012. Despite my efforts, the validation does not seem to work as intended. To troubleshoot this problem on a smaller scale, I decided to create a new MVC 4 pr ...

Adjust the background color using jQuery to its original hue

While working on a webpage, I am implementing a menu that changes its background color upon being clicked using jQuery. Currently, my focus is on refining the functionality of the menu itself. However, I've encountered an issue - once I click on a men ...

Transfer information through ajax to Jquery dialog box

Can anyone help me with an issue I'm facing while trying to post data from my form to a jQuery dialog that loads external content? I've managed to serialize the form data and it appears in the URL, but for some reason the dialog won't open: ...

Monitoring the browser's refresh activity

My web application is based on MVC architecture. Each inner activity is loaded using jQuery AJAX, which fills the data in the same container with each call. If a user clicks the browser's refresh button, I want to reload the data fetched from the last ...

Is there an issue with this piece of jQuery code?

function updateFieldFromUrl(url, param, field) { var anchor = document.createElement('a'), query; anchor.href = url; query = anchor.search.replace('?', '').split('&'); for(var i = 0, keyValue; i < qu ...

The fxFlex property is failing to truncate the span if it overflows

I am encountering an issue with my flex box and its span element. My goal is to truncate the text when it overflows, hiding the overflow without displaying ellipsis. <div fxFlexFill fxLayoutAlign="center center" class="over-line"> <div fxFle ...

What is the process of removing table data from an object?

When I perform edit operations in both the table and object, deleting an entry deletes it only from the table and not the object. The "empobj" button is inserted to view table data; when I edit table data, it updates both the table and object. However, I e ...

Guide on displaying a table in Tabulator utilizing Flask alongside a JSON variable

As a beginner with Flask and JQuery, I'm seeking assistance. My goal is to display a dynamic table by linking the JSON parameter passed in render_template with Tabulator in my HTML page. Below is a snippet of my app.py: import os from flask import Fl ...

Unable to activate the on('click') event when the button is loaded via AJAX

I am facing an issue with the on('click') event. I have a button that is loaded dynamically via ajax and has a click event attached to it. However, when I try clicking it, nothing happens even though the expected output should be showing an alert ...

Controlling a table using JavaScript and jQuery

Implementing this particular functionality in JavaScript/jQuery has been quite challenging. My initial idea involved using numerous ids, but as the content will be dynamic, it makes more sense to utilize classes instead. Consider the table below: <tab ...

IntelliJ automation in Java does not allow clicking the button

Currently, I am on the PayPal page and I need to automate clicking the agree button. <form id="ryiForm" class="proceed ng-pristine ng-valid" ng-class="{true: 'validated'}[validated]" ng-submit="confirm.$valid && onPay()" novalidate= ...

unable to save array using chrome extension storage API

Currently, I am in the process of developing a Chrome extension and utilizing the Storage API. The information regarding this can be found here. To my understanding, it is feasible to store JS objects and arrays through this method. Below is an excerpt of ...

Upon clicking on any child element within Div, the Div itself disappears from view

I created a script that triggers the div to eject and applies the active class to the correct parent element upon clicking. Additionally, I included a feature where clicking outside of the div will close the dropdown. However, I encountered an issue where ...

showcasing a row of 10 items all at once

How do I make my bubble chart responsive? I want to display only 10 bubbles for large screens and have the number of bubbles per row decrease as the screen size gets smaller. I initially tried setting the width of each bubble to 10%, but it didn't wor ...

Which one should I prioritize learning first: ASP.NET AJAX, jQuery, or should I focus

As a .NET developer, I have predominantly worked on server-side development for web-based intranet applications using ASP.NET WebForms. However, I lack expertise in client-side development, particularly with JavaScript and various JS frameworks. Currently, ...