CSS overflow-wrap new property value anywhere usage

CSS overflow-wrap new property value anywhere usage

1. First, understand the overflow-wrap attribute

The CSS overflow-wrap property is actually the previous word-wrap property. MDN now directly jumps word-wrap documentation page to the overflow-wrap property documentation page.

Since the overflow-wrap property is not supported by IE browsers, and other modern browsers still support the old word-wrap property syntax, there is no reason to use overflow-wrap property.

Until one day overflow-wrap property suddenly supported a new property value, anywhere , and overflow-wrap property had a reason to be used.

The formal syntax of overflow-wrap property is as follows:

overflow-wrap: normal | break-word | anywhere

2. What is the use of anywhere

Before we explain the function of the technical attribute value anywhere , let me first give you a basic understanding of the concepts of "hard line break" and "soft line break".

Hard line breaks insert actual line breaks at the break points of the text, while soft line breaks actually remain on the same line, but appear to be divided into several lines. For example, word-break:break-all makes long English words belong to soft line breaks.

The differences and similarities between anywhere and break-word

In its normal state, anywhere behaves the same as break-word , that is, an otherwise non-breakable string (such as a long word or a URL) can be broken at any point if there are no other acceptable breakpoints in the line, and no hyphen is inserted at the breakpoint.

To put it in layman's terms, if consecutive English characters can be separated without breaking, then do so. If this is not possible, then break them. Therefore, compared to break-all, there may be some blank space left. As shown in the following figure:

For details, please refer to this article: "The difference between word-break:break-all and word-wrap:break-word".

Let's talk about the different supports. The difference between anywhere and break-word is that overflow-wrap:anywhere takes soft line breaks into account when calculating the minimum content size, while overflow-wrap:break-word does not.

For example, the following example:

<p class="anywhere">I'm zhangxinxu.</p>
<p class="break-word">I'm zhangxinxu.</p>
p {
    display: inline-block;
    width: min-content;
    padding: 10px;
    border: solid deepskyblue;
    vertical-align: top;
}
.anywhere {
    overflow-wrap: anywhere;  
}
.break-word {
    overflow-wrap: break-word;
}

The result in the Chrome browser is as follows:

It can be seen that the minimum width of the element declared with overflow-wrap:anywhere is the width after each English word is broken, while the element declared with overflow-wrap:break-word is still calculated according to the default minimum width rule.

As you can see, overflow-wrap:anywhere is like a hybrid of overflow-wrap:break-word and word-break:break-all declarations, and is mainly used in flexible layouts, that is, when the element size is sufficient, the words are displayed as much as possible without interruption, and if the size is not enough, they can be broken.

3. Compatibility and Conclusion

overflow-wrap:anywhere declares that the compatibility is not optimistic at present. Currently (March 2020), Safari browser does not support it, and Chrome browser has just supported it. For specific information, see the table:

Therefore, it is not suitable for use in actual projects at present, so you just need to understand it.

Moreover, this attribute is not used in regular text typesetting. Even if you know the value of this attribute, you will not think of using it.

It is destined to be a forgotten CSS feature in the future.

That’s all I have to say. I’ll give you a brief introduction to a new feature.

Summarize

This is the end of this article about the usage of the new CSS overflow-wrap property value anywhere. For more related CSS overflow-wrap new property value anywhere content, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. I hope that everyone will support 123WORDPRESS.COM in the future!

<<:  MySQL8.0.18 configuration of multiple masters and one slave

>>:  Detailed explanation of custom events of Vue components

Recommend

Docker image compression and optimization operations

The reason why Docker is so popular nowadays is m...

Methods and techniques for quickly displaying web page images

1. Use .gifs rather than .jpgs. GIFs are smaller ...

Graphical explanation of the function call of proto file in Vue

1. Compile proto Create a new proto folder under ...

Implementation of installing and uninstalling CUDA and CUDNN in Ubuntu

Table of contents Preface Install the graphics dr...

In-depth understanding of the use of CSS clear:both

clear:both is used to清除浮動This is the impression I...

Docker exec executes multiple commands

The docker exec command can execute commands in a...

A brief analysis of the matching priority of Nginx configuration location

Preface The location in the server block in the N...

React High-Order Component HOC Usage Summary

One sentence to introduce HOC What is a higher-or...

jQuery realizes the shuttle box function

This article example shares the specific code of ...

Solution to the data asymmetry problem between MySQL and Elasticsearch

Solution to the data asymmetry problem between My...

How to monitor array changes in Vue

Table of contents Preface Source code Where do I ...

How to view MySQL links and kill abnormal links

Preface: During database operation and maintenanc...

JavaScript to achieve mouse tailing effect

Mouse effects require the use of setTimeout to ge...