Firefox - Eliminating the x-scrollbar

In Firefox, an unwanted x-scrollbar is appearing.
Even when attempting to disable it using overflow-x: hidden;, the width remains incorrect (strings are still hidden).

.wrapper {
  position: absolute;
}
.left {
  height: 150px;
  display: inline-block;
  position: relative;
  overflow: auto;
}
.left > div {
  white-space: nowrap;
  padding-left: 20px;
}

Chrome View:

https://i.sstatic.net/y6oDl.jpg

Firefox View:

https://i.sstatic.net/MHUGC.jpg

Any ideas why this might be happening?

Feel free to experiment with the code on this jsfiddle: https://jsfiddle.net/5yqkoujm/

Answer №1

Give this code a try:

.container {
    position: absolute;
}
.sidebar {
    max-height: 250px;
    display: inline-block;
    position: relative;
    min-width: auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 20px;  //this solves issue of scrollbar covering content
}
.sidebar > div {
    white-space: nowrap;
    padding-left: 20px;
}

UPDATE: For Mozilla browser compatibility:

.container {
    position: absolute;
}
.sidebar {
    height: 150px;
    display: inline-block;
    position: relative;
    min-width: auto;
    overflow-y: auto;
    overflow-x: hidden;
}
@-moz-document url-prefix() {
.sidebar {
    height: 150px;
    display: inline-block;
    position: relative;
    min-width: auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 20px;  //this fixes scrollbar covering content
}
}
.sidebar > div {
    white-space: nowrap;
    padding-left: 20px;
}

Answer №2

Here's what I think: you'll need to set a fixed height and dynamic width for the left div to adjust to its content.

An element with display:block (like a div) is by default 100% width. Elements with display:inline or inline-block will adjust to their content size.

Try this UPDATED code:

Another update: hides the scrollbar when there are not enough items to display. Finally, it meets your requirements :)

.wrapper {
  position: absolute;
}

.left {
  height: 150px;
  display: inline-block;
  position: relative;
  overflow-y: auto;
}

.left>div {
  white-space: nowrap;
  display: block; /*Fixed it - here's the solution!*/
  padding-right: 20px;
}
<div class="wrapper">
  <div class="left">
    <div>Some short string</div>
    <div>Some short string</div>
  </div>
  <div class="wrapper">
    <div class="left">
      <div>Some short string</div>
      <div>Some long string that needs to wrap aroundSome long string that needs to wrap aroundSome long string that needs to wrap arundSome string</div>
      <div>Some short</div>
      <div>Some short string</div>
      <div>Some short string</div>
      <div>Some short</div>
      <div>Some short string</div>
      <div>Some short string</div>
      <div>Some short string</div>
      <div>Some short string</div>
      <div>Some short string</div>
      <div>Some short string</div>
      <div>Some short string</div>
    </div>
  </div>

Hope this helps :)


Found the solution thanks to this discussion thread: parent div scaling to content inside it

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

Display the div only when certain other divs have been clicked

I am fairly new to jQuery (this is my second attempt at using it). I have searched for solutions on Google and StackOverflow, tried several approaches, but still can't solve the last part of my issue. Any assistance or direction would be greatly appre ...

Navigate to the specified text in the dropdown menu based on the ul li selection

Is it possible to achieve a functionality similar to that of a select box, where typing a keyword that matches an option in the select box will automatically move the pointer to that option? I am looking to implement a similar feature in my HTML code: < ...

Creating a responsive textbox in Bootstrap - tips and tricks!

I am trying to use Bootstrap and I have a Textbox that contains some text. How can I make it responsive, meaning it adjusts to the screen size when I resize the window? When dealing with images, we use the "image-responsive" class, but what about a Textb ...

Restricting the height of a column in Bootstrap 4 to create a more compact design

Currently, I have an element that contains a few columns. The issue is that all columns end up being the same height as the tallest one. What I want is to set a minimum height for one specific column, #colB, and have the other two columns scroll vertically ...

Toggle the visibility of three different div elements using JavaScript on mouseover

Trying to create three image links that display different divs when onMouseOver. <script type="text/javascript> function toggleVisibility(divid) { if (divid==="1"){ document.getElementById("1b").style.visibility = "visible"; document.getElem ...

JQuery: the art of concealing and revealing

My current setup seems to be functioning, but I can't shake the feeling that it's not quite right. CSS: #logo { display:none; } JQuery: $("#logo").delay(800).fadeIn(800); While this configuration works, I'm concerned about whether j ...

Adjusting div container width for better layout

My website is designed with a 640px page-width for mobile devices, like so: html, body { width: 640px; padding: 25px; margin-left: auto; margin-right: auto; } All elements have the same margin on both sides and a padding of 25px. While th ...

Utilizing em units within CSS media queries is producing erratic outcomes on various browsers

My CSS media queries are set up in a progressive manner like the following: * { font-size: 14pt; } @media screen and (min-width:85em) { : : } @media screen and (min-width:110em) { : : } When I have two browsers open on the same screen, with identical siz ...

Disabling the hover effect of a material-ui button within a styled component

I tried adding the css hover property to disable the button's hover effect, but it doesn't seem to be working for my situation. How can I go about resolving this issue? import Button from 'material-ui/Button' import styled from 's ...

Selenium is not functioning properly on the server

My Selenium script was running fine on both my PC and server, but it suddenly stopped working on the server a few days ago. I can't figure out what's wrong. Both Firefox (41.0.2) and Selenium (2.53.5) are set up similarly on my PC and locally. W ...

"Utilizing multiple class names in Next.js to enhance website styling

Looking for a way to apply multiple classNames in Next.js, especially when dealing with variable classnames? I'm following the component level CSS approach. Take a look at my code and what I aim to achieve: import styles from "./ColorGroup.mod ...

Converting CSS specific to a particular vendor: A step-by-step

Looking for a method to adapt a CSS file containing only -moz-css-property references to include compatibility with Chrome, Safari, and other browsers. Ideally seeking a user-friendly web application that can perform this task seamlessly. ...

Pictures do not adhere to the maximum width set on their parent elements

When the max-width CSS style is set on the body tag and an image within the body surpasses this maximum width, the image does not adhere to the set limit. Instead of resizing, it simply overflows. Why does this happen? So, what is the solution to this pro ...

Adding a border with vertical padding above and below two floated divs with different heights

Here is some sample markup: <div class="container"> <div class="one">column a<br />column a</div> <div class="two">column b</div> </div> The content in the inner divs can vary in height and is dynamically g ...

Struggling with color styling within link_to tags in Rails 4 - having trouble getting inline styling to show up correctly

<%= link_to "Sign In", new_user_session_path, :method => :get, style: "color:white" %> <h3>Read More - <%= link_to 'Article', action: :articles, style: "color: purple" %></h3> <%= link_to 'Click to Read More Abo ...

Angular - Modify the Background Color of a Table Row Upon Button Click

I am struggling to change the background color of only the selected row after clicking a button. Currently, my code changes the color of all rows. Here is a similar piece of code I have been working with: HTML <tr *ngFor="let data of (datas$ | asyn ...

Create CSS rules to draw lines that stretch to the edges of the container

As a skilled developer with expertise in CSS and coding styling, I have encountered a new design that has been approved. I am currently working on achieving a specific look with drawing borders and lines that need to extend both left and down. Here is a sc ...

Using data-image as the source for Bootstrap Modal

I am currently working on an image gallery that utilizes the Paver jQuery plugin. The gallery is functional, but I am facing an issue where it displays the same image in the modal instead of showing the respective data-image for each image. My goal is to ...

Adsense ad unit is not responsive and fails to display properly at dimensions of 320x50 px

I have a unique banner ad that I want to display as the footer on my responsive website. Using media queries recommended in the advertising documentation, I am adjusting the size based on different screen widths. Check out the CSS code below: <style&g ...

jQuery conceal input field after it has been displayed

I've created an HTML form with two different sections for search purposes. The first section displays basic fields, and by clicking on "Advanced Search" (in my case, "Расширенный поиск"), additional fields are revealed. Everything work ...