Solve the scroll-view line break problem of WeChat applet

Solve the scroll-view line break problem of WeChat applet

Today, when I was writing a small program, I used scroll-view, but I found that a line of text in scroll-view could not wrap. The code is as follows:

<scroll-view scroll-y style="width:100rpx;height:100rpx;">
asdhadjhkajshdkjahsdkjasdajsdhkajsdkajsdkajsdhasjdaksj
</scroll-view>

I found that a large paragraph of English in the scroll-view is only displayed in one line, and the part exceeding the width cannot be hidden

solve

After searching online for the problem of text not wrapping in scroll-view of mini-programs, I found that the mini-program component has a default style white-space: nowrap; , which does not wrap by default, so I added white-space:normal !important; to override its default style, but it did not work after adding it, so I searched for text wrapping again and found that general text wrapping would add word-break: break-all; After adding it, I found that it did work

word-break

Since I am not a professional front-end developer (I am working hard to become a qualified front-end engineer), I have taken a look at the usage of word-break. The following is my understanding. If there are any mistakes, please correct me.

Syntax: word-break : normal | break-all | keep-all

parameter:

normal: According to the text rules of Asian and non-Asian languages, line breaks are allowed within words. The example I wrote above does not have line breaks because English uses spaces to determine whether to break. In the example, there is a long string of English characters without spaces, so there is no line break. If a space is added in the middle, the line will break at the space. In Chinese, each Chinese character is an independent individual, and each character can be used as a line break marker.

break-all : This behavior is the same as normal for Asian languages. Also allows arbitrary word breaks in lines of text for non-Asian languages. This value is suitable for Asian text that contains some non-Asian text. This value will judge a single English character as an independent individual, and each English character can be used as a line break.

keep-all : Same as normal for all non-Asian languages. For Chinese, Korean, and Japanese, word breaks are not allowed. Suitable for non-Asian text with a small amount of Asian text

Summarize

The above is what I introduced to you about solving the scroll-view line break problem in WeChat applet. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time!

<<:  Detailed explanation of Vue transition effects and animation transition usage examples

>>:  Docker cleanup environment operation

Recommend

Simple example of adding and removing HTML nodes

Simple example of adding and removing HTML nodes ...

Detailed explanation of CSS BEM writing standards

BEM is a component-based approach to web developm...

How to create a Pod in Kubernetes

Table of contents How to create a Pod? kubectl to...

Understanding and using React useEffect

Table of contents Avoid repetitive rendering loop...

How does MySQL achieve multi-version concurrency?

Table of contents MySQL multi-version concurrency...

JS 9 Promise Interview Questions

Table of contents 1. Multiple .catch 2. Multiple ...

How to use Antd's Form component in React to implement form functions

1. Construction components 1. A form must contain...

A brief analysis of the matching priority of Nginx configuration location

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

The iframe frame sets the white background to transparent in IE browser

Recently, I need to frequently use iframe to draw ...

HTML table markup tutorial (16): title horizontal alignment attribute ALIGN

By default, the table title is horizontally cente...