Why does `overflow-wrap: break-words` behave differently from `word-break: break-words` and which one is more effective in certain situations?

What is the distinction between overflow-wrap: break-words and word-break: break-words?

While many sources claim that there is no difference, my personal experiments suggest otherwise:

<!-- truly breaks words -->
<table style="width: 100px; border: 1px solid red">
  <tr>
    <td>
      <div style="word-break: break-word">
        hdsqdhsqydhsqgydqgsydgysqgydsqgydsgqydygsqgydsqgy
      </div>
    </td>
  </tr>
</table>

<!-- does not fully break words -->
<table style="width: 100px; border: 1px solid red">
  <tr>
    <td>
      <div style="overflow-wrap: break-word">
        hdsqdhsqydhsqgydqgsydgysqgydsqgydsgqydygsqgydsqgy
      </div>
    </td>
  </tr>
</table>

https://i.sstatic.net/JUkWx.png

Why does one case function correctly while the other does not?

Answer №1

They are exhibiting this particular behavior due to the presence of tables in this specific context.

Tables do not necessarily conform to a specified width; they can expand based on their content unless table-layout: fixed is applied.

This scenario resembles the discussion found at ,

The distinction lies in how minimum content intrinsic sizes are computed. Soft wrap possibilities introduced by line breaks are considered for word-break: break-word but not for overflow-wrap: break-word. To illustrate the contrast between them, let's consider an element that adjusts according to its minimum content intrinsic size, such as a float:

In this case, it is the behavior related to table width calculation that is causing this, rather than being triggered by a float element.

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

How can I create a parent div with cursor-pointer and apply inline styling to make all child elements

Is there a way to apply the cursor-pointer style to an entire div with inline CSS without it affecting just the white space around the child elements? I have tried using position and z-index without success. I am unable to use an external stylesheet for t ...

Achieve a full-page height navigation bar using CSS

Currently in the process of building a website utilizing CSS and HTML, I have successfully added a navigation bar to the left side of the page using this specific CSS code. However, an issue arises when the screen is scrolled down as the navigation bar doe ...

Upon clicking the link, my hover function was disabled

Hey everyone, I'm running into an issue on my website where a button is not working as expected. Initially, when I clicked the home page button, it changed the background color like I wanted. However, when I tried clicking it again, the background col ...

I just noticed that my website inexplicably has horizontal scrolling enabled

When creating a website with a forum, I encountered an issue where the page can be scrolled horizontally only on the forum page. I am using minimal CSS and primarily Bootstrap for styling. Upon removing the <div class="container col-md-6" st ...

Ways to position an element at the center using Flexbox技

Having some difficulty centering an element in my code using flexbox. It seems to work for everything else, but not here. Any suggestions or ideas? .answer { text-shadow: 0 0 2px gr; display: flex; justify-content: center; border-radius: 5px; ...

Securing PayPal's purchase forms for safe online transactions

Trying to assist someone with a donation issue, but discovered that the source code allows for editing of values in the Paypal button. When selecting 5 points worth $5, it's possible to manipulate the values in the source code of the Paypal form. How ...

Using CSS to create various h1 headings with distinct colors and sizes

I am currently working with CSS and HTML, trying to replicate the design shown in this image: https://i.stack.imgur.com/Uyczp.png Initially, I attempted to achieve this by using multiple h1 tags, but after researching further, I realized that it is gener ...

The information presented in the following content seamlessly complements the captivating banner image

I am facing an issue with my banner image that is supposed to display only on small devices in a specified section. For more details, please refer to the following Stackoverflow Topic However, this setup has caused the content below to overlap and no long ...

Adding a gap between the Bootstrap navbar and jumbotron for better spacing

Upon examining the Bootstrap example provided at: http://getbootstrap.com/examples/navbar/ I noticed there is a gap between the jumbotron and the navbar. After delving into the example's CSS, I found that disabling this rule (twice): .navbar { ...

CSS code for creating thumbnail images that enlarge when hovered over

I currently have a series of thumbnails in a row (within container elements) set to float left. These thumbnails are resized to fit neatly within the row. <style type="text/css"> .thumbnails{ float:left; position:relative; } ...

Introduction screen in a JQuery mobile application for Android devices

I'm currently working on an Android app that utilizes jQuery Mobile within my web-based application. I have multiple pages in the app and I am considering adding a splash screen to display when loading a new page or while the page is being loaded. Any ...

Struggling to utilize Mechanize with Python for choosing options from a dropdown menu on an ASP.NET website

Trying to scrape product information from an ASP.NET page (found at ) using Mechanize in Python. The page contains a dropdown menu with various food brands. Here is a snippet of the HTML code: <fieldset class="pulldownfieldset"> <label>. ...

Retrieving .js file from cache during jQuery.html() execution

Whenever I use a JavaScript file to make a call through jQuery's ".html" function, the URL gets mapped in a way that forces the JavaScript file to refresh. For example: $(".r").html(data+'<script text="text/javascript" src="http://../test.js" ...

Retrieving the title property with the power of JavaScript

https://i.sstatic.net/cp7qK.png My journey into JavaScript is just beginning, and I'm currently immersed in a project that involves using facial recognition technology to detect emotions. While the software successfully detects emotions, I am struggl ...

What is the best way to toggle the visibility of a side navigation panel using AngularJS?

For my project, I utilized ng-include to insert HTML content. Within the included HTML, there is a side navigation panel that I only want to display in one specific HTML file and not in another. How can I achieve this? This is what I included: <div ng ...

Passing information from the created hook to the mounted hook in VueJS

How can I transfer data from the created function to the mounted function in VueJS? In my VueJS application, the code in my created function is as follows: created: function(){ $.getJSON({ url: 'static/timeline.json', success:function( ...

The resizing issue of Textarea during transitions

Whenever I add the transition property to a textarea, it automatically affects the resizing function of the textarea. Is it possible to disable the transition only when resizing the textarea, but not for the textarea itself? <textarea name="" id="" cla ...

Adjust the color of the text in Ionic based on the condition

My current solution involves highlighting text in a small slider after a user tap, but it feels very makeshift. <ion-slide *ngFor="let loopValue of values"> <div *ngIf="viewValue == loopValue"> <b> {{loopValue}} </b> ...

Header Button and Dropdown Divs Alignment

Currently, I am working on creating a three-button system to showcase the collectibles in my game's website. I have the buttons prepared, but the one on the right flies off the screen, and the middle button appears misaligned. My goal is to design a ...

What causes the unusual behavior of `overflow-x: auto;` when used within a parent element with `flex-direction: row;` styling

I have gone through numerous other queries regarding horizontally scrolling tables, but none seem to address this particular problem. When using a responsive table in the default Blazor Server template of a new project built with Bootstrap 4, the browser ...