Is there a Safari glitch related to floating elements?

I stumbled upon a strange issue with the layout I've been working on, and it led me to this concise code snippet that seems to be causing misrendering in desktop Safari. It appears that the div#shim element is what's triggering the text misrender. Has anyone encountered this problem before or found a solution?

<div id=shim style="float: left; height: 3px; outline: thin solid blue;"></div>
<div style="float: left; clear: left; width:50%; height: 50px; outline: thin solid red;">50%</div>
<div style="float: right; clear: right; width:10%; height: 50px; outline: thin solid red;">10%</div>

Here is some text to show the bug. 
Here is some text to show the bug. 
Here is some text to show the bug. 
Here is some text to show the bug. 
Here is some text to show the bug. 
Here is some text to show the bug.

https://i.sstatic.net/7s5nh.png

Answer №1

The settings in the two floated divs are causing confusion.

Interestingly, they seem to have a counter-intuitive effect. In Safari, the text flows into the right floated div starting from the first line and continuing for the total width.

Removing the clears appears to fix the issue.

If you do want everything cleared before displaying anything else, adding a clear: both after the text should solve the problem (as shown by additional text following it).

Tested on iPad with IOS14 Safari, it works whether the text is too short to flow under the floated divs or long enough to fill the space between them and flow under.

<div id=shim style="float: left; height: 3px; outline: thin solid blue;"></div>
<div style="float: left; width:50%; height: 50px; outline: thin solid red;">50%</div>
<div style="float: right; width:10%; height: 50px; outline: thin solid red;">10%</div>

Here is some text to show the bug. 
Here is some text to show the bug. 
Here is some text to show the bug. 
Here is some text to show the bug. 
Here is some text to show the bug. 
Here is some text to show the bug.
<div style="clear: both;"></div>
This is some stuff coming afterwards to show that it clears both the text and the red bordered divs no matter what the length of the text between those divs is.

Answer №2

After experimenting with various techniques such as word break and adding divs, I have discovered that Safari's behavior differs when laying out a line next to a float. It seems that Safari first looks at the left float at the top of the text line only to calculate the width of the line, which results in a conflict with the wider float at the bottom of the line. If Safari were to draw the line where it calculated it, the text would overlap the lower float. However, during drawing, Safari places the left edge at the rightmost float on the line correctly, causing the text to extend off the right side of the screen or even start there. This same issue is observed with the use of shapeOutside as a regular box.

On the other hand, Chrome, Firefox, and Edge all display the correct calculation by taking into account the height of the floats within the line. Consequently, I can conclude that this discrepancy in text calculation within Safari may be considered a bug without any feasible design or CSS workaround. Regardless of the approach taken, if the body text intersects between two floats where the lower one is wider, the resulting line will either be too long or, in the case of a 100% width lower float, start beneath the scroll bar.

<div style="float:left; clear: left; width: 50px; height: 0.3em; background: red;"></div>
<div style="float:left; clear: both; width: 100px; height: 0.3em; background: green;"></div>
<div style="float:left; clear: left; width: 25px; height: 0.3em; background: blue;"></div>
1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 

https://i.sstatic.net/98AY7.png https://i.sstatic.net/0nIIt.png

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

Retrieve the targeted row from the table and then employ a function

Here is a datatable that I am working on: http://jsbin.com/OJAnaji/15/edit I initially populate the table with data and display it. Then, I add a new column called "kontrole." data = google.visualization.arrayToDataTable([ ['Name', &apo ...

What is the method for positioning a logo image, phone number, and location above the navbar using bootstrap?

I just started learning Bootstrap and I am trying to add a logo image, location image with address, and phone number with text above the navigation bar. I want all these elements to be centered on the page. However, my current attempt is not achieving the ...

Mastering the Art of Scrolling to a Specific Div with jQuery Animation

I've been searching for a solution on stack overflow, but because I'm not very proficient in jquery, I haven't been successful. My question is, how can I smoothly scroll from the top of the page to a specific div? I've successfully ach ...

Executing a Javascript function when a form is submitted

function validateForm() { alert("Form submitted successfully"); return true; } <form onsubmit="return validateForm()" action="add.php" method="post" id="p1"> <center>Add New Survey</center> <p>&nbsp;&l ...

Navigate through the list of options by scrolling and selecting each one until the desired element is

Hey, I've got this AngularJs directive that selects an item based on the "key-pressed" event, and it's working perfectly. The issue arises when there is a scroll bar since the elements get hidden, making it difficult for me to see them. You can ...

Utilizing JavaScript Modules to Improve Decoupling of DOM Elements

Currently, I am tackling portions of a complex JavaScript application that heavily involves DOM elements. My goal is to begin modularizing the code and decoupling it. While I have come across some helpful examples, one particular issue perplexes me: should ...

How come my div is taking on the height of something that isn't its direct ancestor?

I am in the process of creating a website that features a consistent design element of an inset border surrounding a block of content within a <div>. This inset border is achieved using LESS/CSS, and is contained within a separate <div class="inse ...

Unable to retrieve form values in PHP after submission via POST method

I am facing an issue with the HTML form below. When a user submits it, the PHP code in contactengine.php is triggered. However, the values are not appearing in the email I receive or the generated .txt file. <!------------------from start------------&g ...

What steps can I take to stop the comments section on my WordPress website from taking up the entire screen?

After launching my WordPress website, I noticed that the comments section under each post is stretching across the entire width of the screen, instead of aligning with the margins like the rest of the page. Can someone advise on how to adjust the margins ...

Issue with margin-top not meeting set expectations

To assist in providing assistance, I have put together a quick jsfiddle project. I am curious why the use of margin-top for #container causes the entire body to be pushed down from html, rather than just pushing #container away from #containerWrapper. Th ...

What is the process for adding a naked domain (without www) on GoDaddy that is deployed through Heroku?

I have successfully deployed a domain through Heroku, and it is functioning properly with the www prefix. However, when attempting to access the domain without the www, it fails to render correctly. I have tried adding both versions of the domain (with www ...

What could be causing the disappearance of my <Div> when applying a Class to the contained <span>?

My goal is to showcase a variable on my HTML page using CSS for a Graphical display in OBS streaming software. Whenever I apply the class .wrappers to the span id p1Name (and p2Name), the text disappears from the HTML output in OBS. I'm puzzled as to ...

Are Firefox and Internet Explorer experiencing issues with CSS rendering accurately?

Experiencing some problems with IE and Firefox CSS To see the issue, visit Check it out in Chrome - it's displaying correctly there But when you view it in IE or Firefox, it's acting strange. Am I making a mistake somewhere? Any help would b ...

html issue with the footer

Just starting out with HTML and encountering some difficulties with adding a footer. The main issue is that when I add the footer, the 'form' element gets stretched all the way down until it reaches the footer - you can see an example of this her ...

Clicking the ASP button does not trigger the onclick event when a web user control is included on the webpage

I have been working on a web form application that I developed using the visual studio template. The template includes a content placeholder that gets replaced by the content of each accessed page. One particular page, which contains server controls like t ...

What do you do when you need to hide a table column that has a colspan

I have been searching for a solution to my unique table structure, but I haven't found any that match my situation. When attempting to hide column A or B, the following code works perfectly: $('table td:nth-child(1),table th:nth-child(1)') ...

Determine the exact width of text without rounding in Javascript

I'm facing an issue with a div element that I'm manipulating using Javascript to change its position. The problem is that it's rounding off incorrectly. #hi{ background-color: blue; width: 2px; height: 10px; position: absolu ...

What is the best way to align the centers of these text pieces vertically next to a toggle switch?

Query: I'm feeling a bit out of practice with CSS, so this might be an easy question. This is the current look of the relevant section on my page. https://i.sstatic.net/Y0hj9.png To make it easier to analyze, I've extracted the code into a JS ...

Experiencing difficulties with JavaScript/jQuery when encountering the 'use strict' error

I have been working on a small function to change the background of an HTML file, but I keep getting the 'Missing 'use strict' statement' error message from JSLint despite trying multiple solutions. Can anyone suggest how to resolve th ...

Bootstrap is not functioning successfully

<!DOCTYPE html> <html> <head> <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e0c01011a1d1a1c0f1e2e5b405f405f">[email protected]</a>/d ...