CSS - Mysterious Gaps Found in Div Block

Below is the code snippet I am currently working with:

    html {
      height: 100%;
      overflow: hidden;
    }

    body {
      height: 100%;
      color: #bdc3c7;
      font-family: Montserrat;
      background-color: #3E4651;
    }

    .nav {
      display: block;
      width: 100%;
    }

    /* More CSS rules... */

</code></pre>
<pre><code> <div class="infoCenter">
        <div class="totalsContainer">
          <h1 class="infoLabel totalPendingLbl">Total Pending</h1>
          <h2 id="#totalPending" class="infoValue" 
    totalPending">$100.00</h2>
          <h1 class="infoLabel totalAvailableLbl">Total Available</h1>
          <h2 id="#totalAvailable" class="infoValue 
    totalAvailable">$500.00</h2>
        </div>
          <div class="listingsContainer">
          <h1 class="infoLabel totalListingsLbl">Total Listings</h1>
          <h2 id="#totalListings" class="infoValue totalListings">10</h2>
          <h1 class="infoLabel listingsSiteLbl">Listings By Site</h1>
          <h2 id="#listingsonGoat" class="infoValue listingsonGoat">6</h2>
          <h2 id="#listingsonStockx" class="infoValue listingsonStockx">4</h2>
        </div>
</div>

Upon inspection, I noticed that the first container in the main container is shifted down by about 10 pixels without any specific rule in my CSS causing it. This issue has persisted across multiple projects and platforms, causing frustration. While the application's unique design may not align with standard browsers, the problem remains consistent. Your insights on this matter are greatly appreciated.

https://i.sstatic.net/lqihh.png

Answer №1

inline-blocks typically align along their baseline, which is usually the last line of text within them. To change this behavior, you can utilize different vertical-align settings like top or bottom. In the example below, I have implemented top for both .totalsContainer and .listingsContainer.

html {
  height: 100%;
  overflow: hidden;
}

body {
  height: 100%;
  color: #bdc3c7;
  font-family: Montserrat;
  background-color: #3E4651;
}
...
...
<div class="infoCenter">
  <div class="totalsContainer">
    <h1 class="infoLabel totalPendingLbl">Total Pending</h1>
    <h2 id="#totalPending" class="infoValue" totalPending ">$100.00</h2>
          <h1 class="infoLabel totalAvailableLbl ">Total Available</h1>
          <h2 id="#totalAvailable " class="infoValue totalAvailable ">$500.00</h2>
        </div>
          <div class="listingsContainer ">
          <h1 class="infoLabel totalListingsLbl ">Total Listings</h1>
          <h2 id="#totalListings " class="infoValue totalListings ">10</h2>
          <h1 class="infoLabel listingsSiteLbl ">Listings By Site</h1>
          <h2 id="#listingsonGoat " class="infoValue listingsonGoat ">6</h2>
          <h2 id="#listingsonStockx " class="infoValue listingsonStockx ">4</h2>
        </div>
</div>

Answer №2

Consider aligning the boxes by utilizing the following CSS code:

.infoCenter {
  display: flex; 
}

If you're comfortable with using flexbox, this method can be quite effective.

By implementing this approach, you can eliminate the need for

display: inline-block; height: 100%; vertical-align:top;
within the inner containers. Flexbox's default align value is "stretch," which results in all elements having equal height.

Answer №3

Attempting to align them side by side can be achieved by applying the float left property to your totalsContainer:

.totalsContainer {
    margin-top: 0px;
    display: inline-block;
    border: 1px solid white;
    height: 100%;
    float:left;
}

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

Troubleshooting Bootstrap Column Display Issues on Mobile Devices

I used bootstrap columns to organize my users' information. While they look good on larger screens like laptops and desktops, on smaller phone screens the second column appears to have some excess margin at the top. How can I fix this issue? <div ...

Display a div upon loading with the help of Jquery

Two divs are causing me trouble! <div id="loader"> </div> and <div id="wrapper"> </div> "The wrapper div is not located inside the loader div just to clarify." This is my code: $(window).bind("load",function() { $(&apos ...

Looking to retrieve HTML elements based on their inner text with queryselectors?

I am looking to extract all the HTML divs that contain specific HTML elements with innerText = ' * ' and save them in an array using Typescript. If I come across a span element with the innerText= ' * ', I want to add the parent div to ...

"Experience a unique website layout with varying designs on desktop and mobile devices while using the React technology to enable desktop

Just starting out with React and I've noticed something strange. When I view my website on a PC, everything looks normal. However, when I switch to the desktop site on my phone, things appear differently. It seems like moving an element by 20px on mob ...

Need to know how to retrieve the li element in a ul that does not have an index of 2? I am aware of how to obtain the index greater than or less

I'm looking to hide all the li elements except for the one with a specific index. I've written some code to achieve this, but I'm wondering if there's a simpler way using jQuery. While jQuery provides methods like eq, gt, and lt, there ...

JavaScript Password Form Submission - Enter your password in the form

I need assistance with setting up a password for a form. Users should be able to enter a password into a specified field, click submit, and if the password is correct, they will be redirected to buybutton.php in the same window. If the password is incorr ...

Is there a way to customize the checkout page using JavaScript?

I'm working on a checkout page where fields need to change based on a selected radio button. There are two options: A and B. When A is selected, I want certain fields to remain visible while others disappear, and vice versa for option B. Although I p ...

Trouble with CSS loading due to div in Visual Studio MVC

Currently, I am working with Visual Studio 2013 MVC and have a situation regarding the styling of my navbar in _Layout. The navbar includes a messages dropdown menu that utilizes CSS and JS extensively. Interestingly, when I load the messages as a partial ...

Creating additional columns in a database table with PHP and SQL

        I'm currently working on a feature that enables me to add a new column to a database table using SQL and PHP. My setup includes a front-end form where users can choose the table they want to modify and input boxes for specifying the new c ...

Avoid clicking on links while the webpage is still loading

I am facing an issue with my website where I need to intercept link-clicking events using jQuery. Everything works fine, but there is a problem if a user clicks on a link before JavaScript finishes loading, causing it to redirect to another page in error. ...

Using CSS to rearrange the order of specific div elements with the nth-child() selector when targeting different

I am attempting to design a centered navbar for a webpage. The navbar consists of 5 divs and my goal is to have the third div become the first one when the screen size goes below 600px. Here is the HTML code: <div class="mainmenu"> < ...

Trouble with Metro UI Library: CSS not loading properly

I am having trouble with the navbar CSS on my website while using the Metro UI CSS library. Check out my HTML code: <!DOCTYPE html> <html lang="en"> <head> <title>TelePrint Blog</title> <link rel="stylesheet" href= ...

Tips for altering the color of an activated Bootstrap dropdown toggle

When the Dropdown menu is open, I would like to customize its default colors. Specifically, I want to change the border color and background using CSS. https://i.sstatic.net/vKwLE.png Below is the HTML code snippet: <div class="row menu"> <ul ...

Conflict between jquery and hoverIntent libraries

I've encountered an issue with a website that was functioning properly until we added a new form to a specific page. The form, created by another person, utilizes javascript/jQuery for processing. Since adding this form, it has caused the majority of ...

Is there a way to adjust the transparency of an image without affecting any overlaid text while using Bootstrap's carousel feature?

I am currently working with Bootstrap v4 to build a carousel featuring an image with caption text. My goal is to have the image faded while leaving the text unaffected. Despite trying several non-Bootstrap solutions, I have been unsuccessful in achieving t ...

Is it possible to modify the colors of a box and text when hovering over it?

I am currently working on a styled subscribe button and have encountered an issue. I want the background color of the entire box to change, along with the text color, when hovering anywhere on the box. However, my current code only changes the text color w ...

Replace the default focus state using CSS or resetting it to a custom style

I'm looking for a solution similar to a CSS reset, but specifically for the :focus state. If such a thing doesn't exist yet, I'm interested in learning about the possible properties that can be reset or overridden in order to create a new :f ...

Creating and launching multiple tabs in node.js (cloud9 IDE): A step-by-step guide

I am currently working on a choice provider. This program will take a (choice) program with a variable number of choices. For example: Let's say we want to make a coffee with two choices - 1. <light, dark> ...

Guide on accessing a method from a div element in VueJS

Is there a way to only render a div based on a specific condition and call a method when the condition is true? Here's an example of what I'm trying to achieve: <div v-if="timetable === null" @click="mymethodhere"> ...

Opting for CSS3 transitions over jQuery animate

Currently, I am working on animating a block of HTML that involves fading in (opacity) and slightly moving from the left (margin-left)... $('.latest-stats').delay(1000).animate({ opacity: 1, marginLeft: '55px' }, 1000, function () { ...