CSS inline blocks creating additional gap between two vertical divisions

I am facing an issue with extra space between two div elements of class "badge" when displayed vertically in Firefox and IE, while it works fine in Chrome.

I want to ensure that there is either no space or equal space between the div elements in all browsers.

Example on JSFiddle

HTML:

<div class="stat-badges">
    <div class="badge">
        <div class="stat-num">123456</div>
    </div>
    <div class="badge">
        <div class="stat-num">0</div>
    </div>
</div>

CSS:

.stat-badges {
  text-align: center;
  width: 55px;
}
.badge {
  display: inline-block;
  padding: 2px 4px;
  color: #ffffff;
  vertical-align: baseline;
  white-space: nowrap;
  background-color: #999999;
}
.badge .stat-num {
  max-width: 30px;
  min-width: 20px;
  padding: 3px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

The extra space disappears if I remove overflow: hidden;. However, I need to keep overflow: hidden for long text cropping using ellipsis.

Answer №2

display: inline-block; is causing issues here. Try using float: left; instead (you may also want to add clear: left; to ensure each badge appears on a separate line). Check out the example on jsFiddle.

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

Struggling with removing the unattractive left border on my Tumblr page

I am currently working on the website www.fashiontogo.ca To see the source code, please use Google Chrome's feature to view the source since I cannot provide the HTML or CSS directly here. The site is not my own creation, and I did not develop it fro ...

A fleeting moment reveals a broken image tag

How can I prevent the broken image tag from briefly appearing when the page loads? Take a look at this example: http://jsfiddle.net/v8DLe/196/ I have already implemented: onerror="this.style.display ='none'" Is there a way to still use the img ...

The challenge of using CSS Flexbox to position the logo with a margin-top

While learning flexbox, I encountered a challenge. I aim to center align h1, p, and button elements, with the logo positioned at the top margin-top of 1em. Essentially, I want the h1, p, and button to be centered, while the logo is positioned at the top wi ...

Issue with opacity transition in CSS3 triangle's :before pseudo-element persists

I have added a :before to the anchor in my code to create a CSS triangle. My goal is to have an opacity transition that displays the triangle when hovering over the anchor. However, I've noticed that if you quickly hover over the link, it skips the tr ...

Switch up the design on Bootstrap 4 navigation tabs

Trying to customize the appearance of the current tab in a nav-tabs setup has been a bit challenging. I've created a simple file to test this functionality. When a tab is clicked, the content switches correctly, but I'm struggling to apply specif ...

I'm using Bootstrap (version 5.3) and when I tried to replicate the features from the examples, I noticed that the background isn't being copied over

I encountered an issue today while working on a website using bootstrap. I was copying features from examples in the bootstrap section, but when I pasted the code into my coding platform, the background appeared transparent and did not display as expected. ...

The image is failing to display in the CSS

As a beginner in the world of CSS and HTML, I encountered an issue where my background image is not showing up. Here's the code snippet that I have: ... <style type="text/css"> #header_contain{ width:935px; height: 135px; ...

What could be the reason for the absence of this Javascript function in my attribute?

I have been working on an app using electron, and I have a function that successfully adds tabs to the app. The issue arises when I try to add tabs via JavaScript with the onclick attribute - they show up as expected but do not execute the code to hide and ...

Array of Ascending Progress Indicators

I currently have a progress bar that I'm happy with, but I want to enhance it by incorporating stacked progress bars. My aim is to have the progress bar behave in the following way when an option is selected: https://i.stack.imgur.com/Pw9AH.png & ...

Ways to eliminate unnecessary spacing in CSS text-stroke

I am trying to achieve a text-stroke effect with transparent text over an image. However, I am facing an issue where the text-stroke also displays lines within the text itself. I am using the Montserrat font from Google Fonts. Can anyone provide assistance ...

When adjusting window size, the input shifts towards the left

Is there a way to prevent my input and login button from moving to the left when resizing the window? I am new to HTML and CSS and would appreciate any tips on keeping them in place. Below is my CSS code: #absolute { position: absolute; top: 411px; le ...

Is it possible to create a customizable class element in HTML that can be used by a CSS file to extract unique values?

Take for instance, if I want to generate text in HTML with the color blue and a size of 13px. Is there a method by which I can achieve this: <h1 class = "blue 13px">Hello</h1> And then apply CSS to give it a blue color and size of 1 ...

What is the best way to adjust the z-index when hovering over an li element

In my <ul>, each <li> contains an image. I want these images to scale and become opaque upon hover. However, the issue is that when they scale, they get covered by the following image. Unsure if the z-index is correctly placed... Below is the C ...

Issue Encountered While Loading CSS using Webpack and Babel

I am currently working on a SSR React App using Webpack3 and Babel6. However, when I launch the server, it is not able to locate any css file (Error: Cannot find module './file.css'). Here is an overview of my current folder structure: src/ | ...

Differences in sub column heights within Bootstrap grid system

I am facing an issue with maintaining consistent heights for all my columns. I typically use Bootstrap to adjust their sizes, but the problem arises when using sub divs. Click here to view a DEMO showcasing the issue The first "table" is borrowed from an ...

Is it possible to include an element id in a CSS URL request?

I have an SVG file containing a series of <symbol> elements, each with unique ids. What I am trying to achieve is to use the background-image property in an HTML file to set the element with the id I choose, like this: background-image: url(“sprite ...

Datalist not displaying options in Chrome browser

I sent a server request to retrieve street names, expecting them to appear as options in a datalist. However, in Google Chrome, they did not display correctly. On the other hand, Firefox and IE showed the correct street names. Here is the code snippet: He ...

The positioning of drawings on canvas is not centered

I'm facing an issue while attempting to center a bar within a canvas. Despite expecting it to be perfectly centered horizontally, it seems to be slightly off to the left. What could possibly be causing this discrepancy? CSS: #my-canvas { border: ...

Choose the option for overseeing safaris

Hello there! I need some help with Safari. Can you please guide me on how to disable the arrows? https://i.stack.imgur.com/1gzat.png ...

Looking to include a toggle button in the menu for both desktop and mobile versions using Bootstrap

When viewing the website on a mobile device, the menu appears as a toggle button. However, on desktop, the menu is displayed without the toggle. Is there a way to show the menu in a toggle button on the desktop version using Bootstrap? ...