Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9201881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:07:30+00:00 2026-06-17T23:07:30+00:00

I’m having a fairly complicated layout issue that only occurs on Webkit browsers. Have

  • 0

I’m having a fairly complicated layout issue that only occurs on Webkit browsers. Have a look at this screenshot:

enter image description here

First, allow me to explain what I am trying to do here. The purpose of this layout is to show a grid of images, with each grid cell being square. The layout is responsive, so on another viewport width, there may be 3 images per row instead of 2.

Technically, the markup is a list of figures, and within each figure is a link, and within the link is the actual image. Pseudo markup:

<ul>
<li><figure><a href=""><img src="" width="0" height="0" /></a></figure></li>
<li><figure><a href=""><img src="" width="0" height="0" /></a></figure></li>
</ul>

As you can see, the innner image does not have any width. This is intentional, because the width is set on the li element, which I use as the image container. In the example viewport as seen in the screenshot, the width of the li element is set to 50%.

Next, during runtime, I hide the img element alltogether and set its src path as background image on the “a” element. The purpose of this is to center the image correctly, regardless of the image’s dimensions or aspect ratio.

Major note: I am using box-sizing:border-box on all elements.

Now, during this runtime routine I also calculate the height of the “li” element dynamically in order to enforce it to be square. Let us assume for a moment that the example screenshot has a viewport width of 400 pixels. Since all “li” elements are set to have a width of 50%, they should have a width of 200 pixels. Knowing this, I simply set the height of this “li” element to 200 pixels as well, making it a square container:

// applied to all "li"s in the list
$(this).height($(this).width());

This works perfect in every browser I tested, except for Webkit browsers (Chrome, Safari). When I output the width of the “a” (or li) element before setting it, both the width and the CSS width, non-webkit browsers will report the exact same width for every “a” element. When I look at the console in webkit browsers, there are variations in their widths. One “a” element may be 200px whilst the other is 191px. The actual values and whether it occurs at all depends on the viewport width of the browser so it seems.

Either way, the result are the ugly gaps you see in the screenshot. What happened is that due to webkit unexpectedly reporting different width for these “a” containers (although they are all set to 50%), the height will also have varieties, causing the gaps.

The big question therefore is: why does webkit report incorrect and different widths for “a” elements that are all set to 50% of the same parent, whilst other browsers don’t?

Theories so far

Hereby a few things investigated so far:

I am using inline-block on the li elements, which is known to cause additional “space”. I have solved this by removing the whitespace from the markup. Either way, inline-block is not the issue, since when I change the “li” elements to float, webkit browsers still show different widths when they shouldn’t.

Another theory has to do with the order of loading things, where some claim delaying my image background runtime routine to the window.load event may help. Unfortunately, the result is exactly the same.

I’m also aware of the difference between .width() and .css(“width”) in jQuery (I’m using 1.8.2). It does not make a difference, since I output both on the console, and Webkit gets both values wrong.

Summarizing

Sorry for the long explanation, hereby a summary: I set a width of 50% (or 33.3333%, depending on the viewport width) on list elements and then retrieve the actual pixel width during runtime. For some mysterious reason, webkit browsers report different widths, allthough all the list elements have the same percentage width.

Finally, here is a live link of the issue:

[removed, due to issue solved and live code changed now]

To reproduce the issue, you have to use a webkit browser and resize your window roughly to that of my example screenshot. It seems to happen at arbitrary viewport widths.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:07:31+00:00Added an answer on June 17, 2026 at 11:07 pm

    It looks to me like it has to do with whether or not the pixel width of the viewport is divisible by 2 or 3. In cases where the width:50% and $(document).width()/2=0 then there is no issue, but when $(document).width()/2=1 then the gap appears.

    So instead of calculating the height for each perhaps you can calculate it once and use it each time, i.e. change imageLayout() to:

    var aHeight = $('.photos li figure > a')[0].width();
    $('.photos li figure > a').each(function(index) {
        console.log('w: ' + $(this).width() + " css w: " + $(this).css("width"));
        console.log('pw: ' + $(this).parent().parent().width() + " css pw: " + $(this).parent().parent().css("width"));
        $(this).height(aHeight);
    
    
        if ($(this).attr('data-loaded') != "1") {
            var imgcaption = $(this).parent().find('figcaption a');
            imgcaption.html('<em class="icon-bolt"></em> loading...');
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.