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

  • SEARCH
  • Home
  • 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 9192969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:03:09+00:00 2026-06-17T21:03:09+00:00

I stumbled upon a difference in layout rendering between Safari and Chrome/Firefox and I

  • 0

I stumbled upon a difference in layout rendering between Safari and Chrome/Firefox and I don’t know which one is “right”.

You can check the jsfiddle here

On Firefox/Chrome the layout is as expected, the yellow div is right after the red ones. But on Safari, the yellow div is positioned under the red ones.

After investigating what I did wrong I found out the bug comes from the CSS class E whose property margin-right (value: -11px) is bigger than the width property (value: 10px) for my div.

I think I understand why Safari renders it this way. The width of div of class B is computed as being the sum of the widths of its children as they have the property float: left;.

Here it is widthB = widthB2*2 + widthE + marginRightE + widthC or marginRightE < -widthE so widthB is not large enough to contain each div next to each other.

So my questions are:

  1. Am I right in my understanding of what Safari does?
  2. Why do Chrome and Firefox render differently? Are they just not decreasing the width of the parent div based on a negative margin-right?
  3. Would the proper correction to always have a margin-right lesser or equal to the width of a div in this case?

Thank you!

HTML:

<div class="A">
  <div class="C">
    <div class="B">
      <div class="B2"></div>
      <div class="B2"></div>
      <div class="E"></div>
      <div class="C">
        <div class="D"></div>
      </div>
    </div>
  </div>
</div>

CSS:

.A {
  background-color: blue;
  height: 200px;
}

.B {
  height:100px;
}
.B2 {
  background-color: red;
  height: 100px;
  width: 100px;
  float: left;
}
.C {
  float: left;
}
.D {
  height: 40px;
  width: 40px;
  float:left;
  background-color: yellow;
}
.E {
  height: 50px;
  width: 10px;
  position: relative;
  left: -10px;
  margin-right: -11px;
  background-color: black;
  float: left;
}
  • 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-17T21:03:10+00:00Added an answer on June 17, 2026 at 9:03 pm

    I’m not sure what you expect to happen with the CSS in the JS fiddle. You are delving into undefined behaviour. I say this because:

    • ‘C’ is floated but does not have a defined width. This leads to issues in various browsers depending on the complexity of the layout.

    • None of the floated elements are ever cleared. When floating it is imperative that a clearfix of some description is used, whether it is clear:both, etc.

    If you tweak the mark-up and add a clear-fix, you see that the content is always 239px. See http://jsfiddle.net/eaFn9/

    However, it seems like the relatively positioned item ‘E’ and margin is having a negative impact on the width calculation, as Chrome’s web inspector seems to always report oddly for the negative margin on this element.

    If you play around with this in web inspector you can see it’s almost as if the negative margin is the cause of the drop. I think it may be due to a container that does not have a width, and isn’t position relative in itself.

    How to fix?

    Personally, I would want to re-write your layout to include fixed widths on all floats, reduce nesting of floats and clear where possible. It seems overly complex but without a real world use case it’s hard to rewrite.

    However, It seemed to me that you can wrap ‘B2’ + ‘E’ elements in a wrapper that is floated and relatively positioned, then use absolute positioning on ‘E’ to give the same affect and remove the negative margin.

    This is the JSFiddle I came up with: http://jsfiddle.net/jV3Ub/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I stumbled upon a question (in a test) about which aggregate functions are applicable
I stumbled upon this question: 7 power 7 is 823543. Which higher power of
I'm writing a script in AutoHotKey, and I've stumbled upon an impasse. Right now
I recently stumbled upon this blog post, which states that Array#uniq behaves differently on
In one of the Delphi demo applications, I've stumbled upon some syntax that I
I stumbled upon a documentation where COM objects have two kinds of interfaces, one
I just stumbled upon this issue and i can't think of a solution I
I'm messing around with QUnit and there is one thing I stumbled upon. I
I stumbled upon this many times, never found a solution. A UINavigationController's navigationBar can
I just stumbled upon a change that seems to have counterintuitive performance ramifications. Can

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.