Chrome-derived web browsers are failing to properly display the <span> element when pre-wrap is configured

Consider the following snippet of HTML...

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <style>

    /* Code blocks */
    div.code {
      white-space:pre-wrap;
      display: table;
    }

    /* comment */
    div.code span.comment {
      white-space:pre-wrap;
    }

  </style>
</head>
<body>
    <div class="code">
12345678
    main()
    {
        int a;
        <span class="comment">// Comment a1</span>
        <span class="comment">// Comment a2</span>

        int b; <span class="comment">// Comment b1</span>
        <span class="comment">// Comment b2</span>

        int c; <span class="comment">// Comment c1</span>

        <span class="comment">// Comment c2</span>
    }
12345678
    </div>
</body>
</html>

Upon viewing this content in Firefox, it appears as expected...

12345678
    main()
    {
        int a;
        // Comment a1
        // Comment a2

        int b; // Comment b1
        // Comment b2

        int c; // Comment c1

        // Comment c2
    }
12345678

However, when displayed in MS Edge (or other Chrome-based browsers), the rendering is slightly off...

12345678
    main()
    {
        int a;
        // Comment a1// Comment a2

        int b; // Comment b1// Comment b2

        int c; // Comment c1// Comment c2
    }
12345678

The issue here lies in how 'pre-wrap' behaves between consecutive <span> elements, even with a blank line separating them like between "Comment c1" and "Comment c2". Removing the CSS definition for span "comment" doesn't resolve the problem, and inserting a newline WITHIN but at the end of the text disrupts the layout in Firefox, which is not a viable solution. Any insights on what could be causing this discrepancy? Is it a browser bug or something else entirely?

Answer №1

If you want this to work properly, try the following: comment out the CSS / display: table;/**. This will impact the result :

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <style>

    /* Code blocks */
    div.code {
      white-space:pre-wrap;
    /* display: table;*/
    }
    /* comment */
    div.code span.comment {
      white-space:pre-wrap;
    }
  </style>
</head>
<body>
    <div class="code">
12345678
    main()
    {
        int a;
        <span class="comment">// Comment a1</span>
        <span class="comment">// Comment a2</span>

        int b; <span class="comment">// Comment b1</span>
        <span class="comment">// Comment b2</span>

        int c; <span class="comment">// Comment c1</span>

        <span class="comment">// Comment c2</span>
    }
12345678
    </div>
</body>
</html>

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

Using jQuery, prevent the user from entering text into an input box when a checkbox

In my project, there is a checkbox that determines whether an input box is disabled. The issue arises when I try to disable the input based on the database value. For example, when the value is 0, it should display as disabled false; however, the input rem ...

Creating a div that automatically scrolls along with the page as it reaches the edges of the viewport

My website features a floating box on the side of the page (Parent div) housing a child div with a position:sticky property that scrolls along with the page as it reaches the top of the viewport. See it in action here: https://codepen.io/Xanthippus480/pen/ ...

Show the exact file name for the CSS file being generated by grunt-contrib-compass

I need help specifying the output name of the CSS file in my grunt-contrib-compass task. Currently, it outputs as index.css. Current Output <%= yeoman.app %>/specialdir/themes/index.css Desired Output <%= yeoman.app %>/specialdir/themes/my-th ...

Transform HTML Response into PHP Array

When I make a web call in PHP, the response I am receiving is unlike anything I have encountered before. Despite trying both the json_decode function and the parse_str method, I am unable to extract the values into an array. My goal is to create an array ...

Generate a hyperlink within a paragraph

Can anyone provide tips on how to turn a string from Json into a paragraph with a hyperlink included? <p>Dumy Dumy Dumy Dumy Dumy Dumy Dumy DumyDumyDumyDumy abc.com </p> Currently, the paragraph displays as is, but I would like to make abc.c ...

Endlessly tapping through each tab with no direction

I am attempting to click on all unopened tabs (elements) randomly across this page. While the code below usually does the trick, it sometimes doesn't click on all elements. I suspect that there might be an issue with how it loads indexes or some othe ...

Updating the CSS properties of a specific element within a dynamically generated JavaScript list

So I'm working on a JavaScript project that involves creating a navigation bar with multiple lists. My goal is to use the last list element in the bar to control the visibility (opacity) of another element. So far, I have been using the following code ...

Customizing R Shiny: Changing the color of a menu item upon selection of any submenu item

Seeking assistance with updating the color of the menuitem in a shiny app to match the active submenuitem. Currently, the active submenuitems are highlighted differently from non-active submenuitems, but we want the main menuitem to also change color when ...

Using both italic and regular text in an HTML (or ASP.NET) textbox can add emphasis and enhance readability for

Is there a way to achieve this using JavaScript? For instance, if the initial text is 'Axxxxxx', I want it to be displayed in a textbox with normal style for the first letter and italic style for the rest like 'A*xxxxxx*' If the initia ...

The button appears flawless in Chrome and Firefox, but unfortunately fails miserably in Internet Explorer. Is there any way to make it functional in all

Check out this JFiddle link: http://jsfiddle.net/Zfnz2/ I'm seeking ideas from the wise minds of the internet. Any thoughts? ...

Change the background color on hover without affecting the text color

I am having some trouble with my code. I can only change the color of the "popup1_btn" button when hovering, but the text color remains the same. If I use .popup1_btn a:hover, it only changes the background and text color of the text, not the entire button ...

Efficiently organizing items within a list on Ionic

Currently, I have an ion-list structured as follows: <ion-list *ngFor = "let chat of Chats"> <ion-item (click) = "openChat(chat.id)"> <ion-label> <h2> {{chat.username}} </h2> ...

How to Eliminate Lower Borders from DataGrid Component in Material UI (mui)

I've been trying to customize the spacing between rows in a MUI Data Grid Component by overriding the default bottom border, but haven't had much success. I've experimented with different approaches such as using a theme override, adding a c ...

What is the best way to design a polygon-shaped responsive div?

I've been attempting to design a unique layout with a pentagon-shaped div, however, I'm encountering some challenges. Despite using SVG for the shape, it does not display correctly in Firefox. Additionally, I need the div to be responsive and sca ...

Issues with Google Chrome truncating the end of lengthy pages

While working on a website project, I encountered an issue with Chrome where loading a lengthy page results in a strange box covering the bottom portion of the content. Interestingly, the same pages appear fine on Safari and Firefox, indicating that the pr ...

What steps can be taken to get the input type color to function properly in IE-11 in the year 202

Is there a way to get the input type color to function properly in IE as of 2020? <input type="color"> I've experimented with several polyfills, but have not had any success. As a final option, do you have a recommendation for an external libr ...

Adjusting CSS using JQuery based on scroll position

I am attempting to dynamically change a CSS style depending on the viewer's position on the page. Despite researching numerous similar threads online, I have not been able to get this code to work as intended. Any assistance would be greatly appreciat ...

Managing concurrent users updating the same form on a web application

Imagine a scenario where user A opens a form with pre-filled data. While user A makes changes to the form data, user B also opens the same form with the data intended for user A. Just as user B begins modifying the data, user A clicks on the submit butto ...

What could be causing my UI Bootstrap datepicker-popup to suddenly stop functioning?

After updating to UI Bootstrap 0.11.0, I encountered an issue where my datepickers were no longer appearing correctly. To demonstrate this problem, I have created a plunker which can be viewed here. Essentially, the code snippet causing the problem is as f ...

Opting for <button> over <a>

I am currently working with ReactJS in conjunction with a Bootstrap Nav Bar. Bootstrap utilizes an <a> tag for the navigation buttons. I am aiming to have the buttons scroll down to a different component on the page without resorting to using an href ...