The <span> element containing "float: right" within the style of "white-space: pre"

Take a look at the code snippet below:

<div style="white-space: pre">
  long time; <span style="float: right;">// know C?</span>
</div>

When this HTML is rendered, WebKit and Gecko produce different results. In WebKit, the contents of the span element stay on the same line as the previous text, while in Gecko they are moved to a new line.

Which rendering is considered correct, and why?

Answer №1

Let's take another shot at answering this...

When using the white-space pre directive, white spaces are displayed literally by the browser. Line breaks, spaces, and tabs are shown as they are written (br tags also act as line breaks). For example:

<div>   hello
world</div>

...will be displayed as:

    hello

world

The float:right directive removes the element from the normal text flow and positions it to the right of its container, allowing text and other elements to wrap around it.

In Firefox, the floated div will fill the available space horizontally, causing it to go to the next line. However, in Chrome, the floated element stays on the same line (although both divs are displayed as block elements taking up the full width). This difference can be seen in this fiddle.

http://jsfiddle.net/k5aueocr/

Since the white-space:pre directive instructs the browser to interpret each character precisely as written, combining it with a span that floats to the right may result in unexpected behavior. Both browsers are following their specifications correctly, but mixing these CSS properties may not produce the desired outcome.

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 way to insert a hyperlink into a specific piece of text?

Here is a list of elements: <ul> <li> <a href="#link1">Text link 1</a> <span>My text contains text: Text link 1, that's it.</span> </li> <li> <a href="#link2">Text link 2</a ...

Craft unique looks for both even and odd Tumblr posts

I recently came up with a unique idea for a Tumblr theme where the design of posts changes based on whether they are even or odd in the sequence. While I have experience with basic HTML coding, delving into Tumblr customization is new to me. Here's wh ...

Ensure the header remains fixed when scrolling in an HTML page with Bootstrap

I created the following code. However, when I scroll down the table, the header disappears from view. I would like the header to always remain at the top, even when scrolling. Despite searching Google multiple times and trying various solutions, I have no ...

The internet browser encountered a JavaScript runtime error (0x800a138f) in which it was unable to retrieve property '0' due to it being either undefined or pointing to a

I'm encountering an issue with my javascript/jquery function that retrieves the selected dropdown value. Everything works fine in Chrome, but when I try to run my application in IE, it throws an error. $("#Application_AppCountries").change(function ( ...

In mobile view, the grid text should be positioned on top of the input field

Created a basic grid layout with input fields. Everything looks fine on the PC, but on mobile devices, long text causes the input field to be positioned below the text. However, when the text is short like Lor, it appears next to the input field... I want ...

Is it achievable to customize the appearance of links with identical classes but distinct title attributes?

Currently updating my website and unable to access the HTML directly. I'm curious if it's feasible to produce various hover effects for image links within parent divs that share the same name but have different title tags. Here is the code snip ...

How can you display Unicode characters within an HTML input element with type=submit value?

I am having trouble displaying a right facing triangle character after the main text on a form button based on a designer mockup. The code snippet causing issues is as follows: <input type="submit" value="Add to basket &#9654;" /> The desir ...

Is it possible to assign a specific color and font style to a title tag?

Is there a way to style a page title with a different color and font in the page tab? For example: title{ color: red; font: 12px tahoma;} I thought it would be interesting to incorporate into websites. I attempted the code above in my CSS file, but it di ...

Is it possible to change the background of a DIV using AJAX/jQuery depending on the numerical value it contains?

Discovering the world of AJAX/jQuery and trying out new things. Check out my fiddle for a better understanding. Each square represents a DIV element. <div class="desk_box_ver" id="desk_B20" data-rel="85" style="left:20px;top:1165px;">B20</div> ...

Is it acceptable for a video to autoplay even if it is not connected to the DOM?

Consider the following three scenarios: document.adoptNode, document.importNode, and document.createElement with assigned properties. In all cases, the video autoplay feature is activated even when it's not connected to the DOM. This behavior diffe ...

Trouble with my dropright Bootstrap menu getting cropped

I am currently working on creating a scrollable sidebar that includes a bootstrap dropright function. The goal is for the menu to appear on the right-hand side when a user clicks on an item in the sidebar. I have successfully implemented the scrollable f ...

Is it possible to showcase CSS and JavaScript code exactly as it appears when the files are saved in their respective formats, but embedded within an HTML

Recently, I've been working with notepad++ and have come across an interesting challenge. In my index.html file, I have embedded css and javascript code. Is there a way to display this code as it appears when saved in their respective files, but maint ...

Internet Explorer 9 exhibits unresponsiveness when clicking on an element within an iframe using Watir/Selenium2

Currently, I am developing automated tests using Watir-WebDriver and Ruby 1.9.2 on an Ubuntu platform for web applications. Within the application, there are iframes containing multiple elements that require interaction. Specifically, I need to click on th ...

What is the best way to align text and an arrow on the same line, with the text centered and the arrow positioned on the

.down { transform: rotate(45deg); -webkit-transform: rotate(45deg); } .arrow { border: solid black; border-width: 0 3px 3px 0; display: inline-block; padding: 30px; } <p>Down arrow: <i class="arrow down"></i></p> Looking to ...

Having difficulty choosing the third option in the dropdown menu

I'm facing an issue with the dropdown menu in my header file that I include on every page of my website. The dropdown list works fine up to the 2nd element, but then it becomes unclickable. I've checked the code for the dropdown list, and it seem ...

Fade-in effect on one DIV element impacting the values of other div

As a newcomer to jquery and JavaScript, I'm facing some challenges in getting the desired functionality. Currently, I am trying to animate three images simultaneously - one moving downward (iphone), another fading in (shadow), and the third one animat ...

Kendo sortable interference with input focus

Utilizing both kendo listview and grid components to display the same information in different views; a primary listview of cards and a table-based grid view, both integrated with the Kendo Sortable widget. The objective is to enable users to edit an inlin ...

What is the process for creating a clickable file upload in Angular?

Currently, I am utilizing the instructions found in this guide to implement a file upload feature in my project. The code provided works perfectly: <input type="file" class="file-input (change)="onFileSelected($event)" #fileUplo ...

The alignment issue with Spring MVC Form Checkbox and Label

I'm attempting to position a <form:checkbox> to the left of a <form:label> using this code snippet: <form:checkbox path="acceptTerms" id="acceptTerms"/> <form:label path="acceptTerms">Accept Terms</form:label> Despite m ...

Populate User Interface Popover - Placement on Compact Display

I have been grappling with finding a solution to position the material ui popover beneath my anchor consistently, even on smaller screens. Take a look at this sandbox example. The current setup is working alright, but the issue is that the scroll is cont ...