Dealing with Safari's overflow problem when using Jquery's width()

Placing a table inside a narrow div with overflow:auto. Across various browsers like Chrome, IE, and Firefox, the width exceeds 200 as expected. However, in Safari, the width is only 100.

Surprisingly, the jQuery width() documentation doesn't address this issue: https://api.jquery.com/width/

To see the problem in action, check out this demo on CodePen and open the console to view the logs: http://codepen.io/anon/pen/adZxrd

If the demo doesn't load properly, here are the code details provided below.


HTML:

<div class="outer">
  <table class="table table-hover table-condensed">
    <thead>
      <tr>
        <td>aaaaaaaaa</td>
        <td>bbbbbbbbbbbbbb</td>
      </tr>
    </thead>
    <tbody></tbody>
  </table>
</div>

CSS:

.outer {
    width:100px;
  overflow:auto;
}

.inner {
    width:200px;
  border:1px solid black;
}

JS:

$('.outer').scroll(function(){
    console.log($('.table').width())
});

Answer №1

After some trial and error, I finally found a solution that worked for me. It turns out there was a max-width: 100% setting on the table (which seemed to be the default), causing a strange issue. Simply changing it to none resolved the problem.

I came across this helpful question that pointed me in the right direction: Help with width calculation in Safari/iOS when elements are overflowing their containers

If you're facing similar issues, feel free to check out my updated codepen here: http://codepen.io/anon/pen/JRjOoy?editors=1111

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

What is the best approach to display white space when the checkbox is not selected, and to split the content by a comma followed by a space when it is

<ul class="dropdown-menu"> <li><a href="#" class="small" data-value="1" tabindex="-1"> <input type="checkbox" id="Speaker1" class="chkCris" value="1" />1</li> <li><a href="#" class="small" data ...

What is the best way to save the authResult object in Vue.js and FirebaseUI once authentication is complete?

I am working on implementing Twitter authentication using FirebaseUI in my Vue.js application. Although I have successfully authenticated the user, I am struggling to figure out how to store information from the AuthResult object. In my main component (A ...

The Tauri JS API dialog and notification components are failing to function, resulting in a null return value

Currently, I am getting acquainted with the tauri framework by working on a small desktop application. While testing various tauri JS API modules, most of them have been functioning as expected except for the dialog and notification modules. Whenever I tes ...

Creating a line using CSS to connect two elements

I've been attempting to divide a series of circles with a line down the center. However, when I position a line (.Line1) to run between the first and last circle, it appears centered at the top left of the first circle instead of being truly centraliz ...

What is a simple way to center a box on a page without relying on margins?

I'm attempting to position a box in the center of the page without relying on margin. Here's what I've tried so far: .box-middle { vertical-align:middle; height:100px; width:100px; border:1px solid #ddd; } This approach h ...

Utilize Jquery and MVC 5 to create a reoccurring partial view

I have a button that triggers the loading of a partial view containing a table with all the categories in my system. <input type="button" value="Load Categories" id="btnLoadCategories" /> This loading process is done via a partial view which is in ...

Struggling to align a div in the middle using react and tailwindcss

Struggling to center a div in React with Tailwind, no matter what method I try. Here is my code: "use client"; import Image from "next/image"; import React from "react"; const LoginPage = () => { return ( <div cla ...

Necessary workaround needed for HTML time limit

Our HTML page has been designed to automatically timeout after 10 minutes of inactivity. This functionality is achieved through the following code: function CheckExpire() { $.ajax({ type:'GET', url:self.location.pathname+"?ch ...

Using jQuery .each() within a PHP foreach loop: A guide

In my code, I have a foreach loop that iterates through an array of images, along with some JavaScript logic to add different classes based on whether the width is greater than or less than the height. The issue I'm facing is that the if function onl ...

Display bootstrap modal hyperlink in web browser search bar

Utilizing bootstrap cards with href tags allows users to click on them and open bootstrap modals. I want users to be able to copy the modal's URL link for sharing purposes, but the issue is that when the modal is opened, the URL remains unchanged. How ...

I encountered an issue with my node/express server where Res.json is causing a

I am encountering an issue with a 100mb object that I am trying to return using a GET request: function completeTask(req, res) { // generates a large object on a child process, then sends it back to the main process res.json(bigObject); // <--- p ...

Tips for implementing a hover effect on the background color of a Bootstrap navbar

I am having trouble changing the background color of links and social media icons when hovering over them. I've tried multiple solutions found through searching, but none seem to work for me. Could someone please assist me with this issue? Thank you! ...

Leveraging jQuery AJAX to execute a php script when a form is submitted

I'm fairly new to this, so please bear with me if this is a silly question. I'm trying to use AJAX to execute a PHP script when a form is submitted (without refreshing the page). When I let the form action call the PHP file, everything works fi ...

I am consistently running into an Uncaught Syntax error within my Express server.js while using Angular 1.5.6

I've been struggling for hours to integrate Angular with routes that I've created. Eventually, I decided to give Express a try and set up a basic server.js file to run as a standalone server. However, nothing seems to be working and I keep encou ...

Steps for adjusting button size in Sencha Touch

How can I resize a button in Sencha Touch 2 to make it smaller? I need to change its height. Any sample code you could provide would be greatly appreciated! Thanks navigationBar: { items:[{ xtype: 'button', ...

CSS grid tracks remain fixed in size while other tracks expand

Why won't the grid track cells dynamically shrink when other cells are enlarged in the following code? In this snippet, hovering over any track section causes that cell to grow to 75% of the viewpoint. However, instead of the other sections shrinking ...

Identifying when a user has inputted incorrect $routeparams

How can I restrict user input to only "id" as a query parameter in the URL? $scope.$on('$routeUpdate', function () { var id = $routeParams.id //check if user has entered any params other than "id". //if yes do someting }); I want ...

Tips for displaying the Bootstrap Navbar in a single line on the xs layout

I am working on a Bootstrap navbar that displays properly in most screen layouts, but I am having trouble getting it to show on one line in the xs layout. Even though there is enough room for it to fit on one line, it keeps breaking up into multiple lines. ...

Exploring Node.js: Comparing Intl.NumberFormat and decimal.js library for floating point calculation

Can someone explain the distinction between Intl.NumberFormat and the decimal.js library? If Intl.NumberFormat can handle currency calculations, what is the purpose of using the decimal.js library and what advantages does it offer over Intl.NumberFormat ...

What is the best method for creating thumbnail URLs for video files in HTML with JavaScript?

I am facing an issue with generating a thumburl for uploaded video files. After dynamically creating an input file and uploading local video files, I am able to retrieve the name and size of the file along with other information as shown in the screenshot ...