Issue with tile size or alignment in Safari

Recently, while creating my portfolio on CodePen, everything was running smoothly except for one little hiccup - Safari.

http://codepen.io/tpalmer75/pen/FijEh (SASS for just one .item element)

.item
  width: calc(100% / 3)
  display: inline-block
  height: 0
  padding-bottom: 25%
  background-position: center center
  cursor: pointer
  overflow: hidden
  background-size: cover

I've tried adjusting the CSS calc functions, box sizing, float, and more. Here's how it appears on Chrome and Firefox.

https://i.stack.imgur.com/8EHz6.jpg

But here is how it looks on Safari:

https://i.stack.imgur.com/crLgX.jpg

Any suggestions or ideas?

Code: http://codepen.io/tpalmer75/pen/FijEh

EDIT

The issue seems to be Safari rounding down all percentages to whole pixels. How can I address this specifically for Safari?

Answer №1

These are two potential solutions to help resolve your issue:

Consider using ems instead of percentages

To tackle this problem, you can implement a technique similar to Squeezemod which utilizes Javascript to calculate the width and height of the browser window and then converts it into ems:

// A function to determine 1em size based on browser dimensions
function squeezemod(){
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var skinnyem = windowWidth / 95;
var fatem = windowHeight / 45;
var ratio = windowWidth / windowHeight;
if (ratio<2.1){
var emval = skinnyem;
}else{
var emval = fatem;
};
$("body").css({"font-size": emval + "px"});
};

// Call the function on window resize
$(window).resize(function(){
squeezemod();
});

Make sure to add the function call in the head section of your HTML document:

<script type="text/javascript">
//squeezemod();
</script>

When using ems for sizing, elements will adjust dynamically based on the browser window's dimensions, including the aspect ratio.

Adjust the calculation as needed to suit your requirements as the Squeezemod method may not provide a perfect solution.

Alternatively, apply a specific border for Safari

Using Javascript, you can apply browser-specific styles to elements with a particular class:

if ( $.browser.safari ){
$(".item").css('xxxxxx', 'xxxxxxx');
};

In the code snippet above, replace 'xxxxxx' with the desired style property like margin: 1px. Utilize this approach to compensate for any width adjustments made by Safari through margins, borders, or other styling options exclusively for this browser.

Answer №2

The grid layout is encountering issues due to the inclusion of calc() functions and percentages.

To address this problem, I have implemented a solution using jQuery where I detect the browser type and adjust each item's width by subtracting 4 pixels.

Visit this link for more details.

 // Identify Safari Browser and make adjustments for better compatibility
  if (navigator.userAgent.indexOf('Safari') != -1 && !navigator.userAgent.match(/(Chrome|iPad|iPhone|iPod Touch)/) ) { 

    alert('You are using Safari desktop.')

    var item = $('.item');
    var page = $('#page');

      item.width(function(){
        return $(this).width() - 4;
      });

      page.width(function() {
        return $(this).width() + 8;
      });

      $(window).resize(function() {


        item.css('width', '');
        page.css('width', '');

        item.width(function(){
          return $(this).width() - 4;
        });

        page.width(function() {
          return $(this).width() + 8;
        });


      });
  }

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

Utilizing ajax to store information in the database

When my image slider loads the next image, I want to save a record in the database. To achieve this, I am using jQuery and AJAX. I store the necessary information in a hidden field called 'data' so that I can send it to my PHP page. function aj ...

When Django comments go wrong: Issues with Ajax and CSRF verification

Having an issue here that seems a bit different from what others have encountered. I've gone through various answers but still no luck. Appreciate any assistance: I've got a list of News items resembling a Facebook feed, and each one has a comme ...

Javascript is handling the JSON Request flawlessly, however, when using Nodejs, an error is encountered with a status

I'm trying to fetch a simple JSON File in NodeJS. Using Javascript and jQuery, it functions perfectly: $(document).ready(function() { $.getJSON('https://www.younow.com/php/api/broadcast/info/curId=0/user=Peter', function(json) { if ...

The jQuery text search/filter feature is effective in most cases, but some fields may not be searchable

Check out the live version here My current setup includes a jQuery search feature that filters cards (divs) based on text found in the details field. However, I want to expand this functionality to include filtering by other fields like title, tags, and s ...

Open the overflow div within a table data cell

My goal is to create a drag-and-drop schedule tool similar to Fullcalendar. I have decided to use a table layout with a rectangular div inside each TD cell to represent tasks. <table onDragEnd={dragend}> <tr> <th>0</th> ...

Eliminate the lower boundary of a divisional table

I'm having an issue with displaying images in a div table. Each image has a border at the bottom, which is around 2-5 pixels wide. Unfortunately, as a new user, I am unable to send any images. My main goal is to remove this unwanted border from the ...

Unexpected issue with codebehind not being invoked by ajax

Within this code snippet, there is a dropdown menu that is intended to trigger a method in the backend when a value is selected. However, the dropdown is not currently functioning as expected. The goal is to make the dropdown menu dependent on selecting an ...

Adjust the size of an input field in jquery or javascript based on user input

Ensure that an input text box can only contain a maximum of 13 numbers, but if the user enters a 14th number as a decimal point, then allow up to 16 numbers. HTML: <input type="text" maxlength="15" onkeyup="checkCurrency(this)"/> Script: func ...

Include an additional phase within the MUI stepper and customize the styling

I am in need of modifying the code below to suit my requirements: Firstly, I would like to change the design from the current one to this: https://i.stack.imgur.com/3RhsH.png The new design will look like this: https://i.stack.imgur.com/sGLwH.png Addi ...

BEM Methodology: Ensuring the CSS value in one block takes precedence over property definitions in another block

I'm facing a challenge with BEM as I try to make properties from one block take precedence over styles in another. Some might suggest adding a modifier for .button, but in some cases, specific properties need to be applied only on certain pages withou ...

Encountering the "G is undefined" error in Jquery when utilizing string.match

Currently, I am utilizing Jquery version 1.3 and have come across an issue with the code. In Firebug, I am receiving an error message stating: "G is undefined." var product = $("#id :selected"); // This pertains to a dropdown element var prodTxt = ...

Access an HTML file in Text Edit on a Mac directly from a web browser

Is there a way to utilize Javascript or another appropriate script to open an HTML file in Text Edit on my Mac? I have created a local web page using Text Edit that has different tabs linking to other Text Edit files within the page. I am looking for a m ...

Can one customize the background color of a segment in a radar chart using Chart.js?

Could I customize the color of the sectors in my radar chart to resemble this specific image? https://i.stack.imgur.com/U8RAb.png Is it feasible to achieve this using Chart.js? Alternatively, are there other chart libraries that have this capability? It ...

Retrieving data from an HTML input tag and storing it in a variable

I'm currently working on a project that involves reading the contents of an uploaded file through an input tag and storing it in a variable. My goal is to then use an algorithm to decrypt the .txt file: <input type="button" value="decrypt" id="dec ...

"Exploring the possibilities of Ajax in conjunction with Sol

I recently completed a tutorial on Ajax Solr and followed the instructions in step one. Below is the code I wrote: header.php: <script type="text/javascript" src="static/js/ajax-solr/core/Core.js"></script> <script type="text/javascript" s ...

ng-click is not triggering my function

I'm really struggling to understand how AngularJS and Typescript can work together efficiently. My main goal is to make a simple method call, but I seem to be stuck due to some constraints in the architecture I have chosen. I must have made a mistake ...

Employing [style.something.px]="2" in Angular to specify the thickness of the border

Presently, I am setting the width of the element using this code format: <div [style.width.px]="size" [style.height.px]="size"></div> What I am aiming for is to utilize a comparable format but to define the border-width css attribute, such as ...

Tips for increasing the size of the SVG icon within Material UI iconButtons

Have you experimented with creating webpages using react.js along with the Material UI library? How can I adjust the size of an SVG icon? Recently, I developed a "create new" component, which consists of a material paper element with an add button on top. ...

jquery accordion not functioning properly following partial ajax page refresh

Initially, I'm using a jQuery accordion that works perfectly. However, I encounter an issue when implementing some Ajax commands to reload part of the page, specifically the inner body section. After the page reloads, the accordion breaks because the ...

get selection choice from the server

I have been trying to update my option select menu when the button is clicked without clearing out the menu. Currently, I am using $(#id).click(function(){}); but it seems that this approach is causing the select menu to clear out. Upon further investigati ...