skip to Main Content

I am working on something that needs to copy text under it and place some tags inside it (<span></span> in my case). Is there any way to make the tags not change the way the text is justified inside the container?

As I simplified the problem here:

<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="UTF-8">
  </head>
<body>
    <div style="position: relative;">
    <div style="position: absolute; bottom: 0; top: 0; text-align: justify; white-space: pre-wrap; width: 800px; font-size: large;">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
    <div style="position: absolute; bottom: 0; top: 0; text-align: justify; white-space: pre-wrap; width: 800px; font-size: large; color:red;">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in <span style="color: blueviolet;">voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis</span> aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
</body>
</html>

You can see that these texts misalign, although they are the same (except one has <span></span> in it). Is there any slight modification (preferably CSS) I can do?

I would also like to point out that I need the pre-wrap, because in the final project I need to interpret "t" and "n" tags.

Edit: This is how it looks on my browser:
here

2

Answers


  1. Well… to me the two divs seem aligned one under each other and they both have text-justification. To check it just go in the browser inspector and show/hide the selected div. I hope I haven’t misunderstood your problem.

    Login or Signup to reply.
  2. I’ve seen your picture and I guess it depends on the browser you are using. I’m on a Mac and I’ve tested in Firefox, Chrome and Safari, with a different text (see pics). Interesting is that Safari and Firefox look the same, while Chrome looks different; that’s why white-space: pre-wrap causes text-align: justify to be ignored, while in Chrome they actually play together.

    It would be useful to know which browser and OS you are using. One possible cause would be that some hidden characters are added to your generated text.

    Safari
    Chrome
    Firefox

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search