On mobile devices, flex layout is very useful. It can automatically adjust the width of the container according to the width of the device. However, I recently found a problem when working on a project: A li element has flex set, flex: 0 0 33.333%, and the text in the child element should be automatically omitted if it exceeds the width defined by flex. <li> <a href=""> <img src="upload/2022/web/5a1692eeN105a64b4.png" alt=""> <p>Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi Xiaomi</p> </a> </li> ul{ display: flex; } li{ -webkit-box-flex: 0; -ms-flex: 0 0 33.333%; flex: 0 0 33.333%; text-align: center; padding: 0 1.333vw; -webkit-box-sizing: border-box; box-sizing: border-box; margin-bottom: 2.667vw; } lip{ font-size: 3.2vw; color: #8F8E94; text-overflow: ellipsis; white-space: nowrap; } At this time, you will find that the text of p may be very long and needs to be hidden on some devices, that is, it does not wrap and leaves an ellipsis... as a mark. Here you will find that text-overflow: ellipsis does not take effect and the ellipsis does not appear at all. And because nowrap is set, you will find that the text will expand the content, causing the content to exceed the screen. So this problem must be solved. Try to cancel the flex: 0 0 33.33% of the parent element .li, but it doesn't work. Try to cancel the display: flex of the ul container, and the ellipsis will appear. Therefore, it is speculated that it is a problem with the flex layout, and further speculated that the ellipsis needs to limit the width of the parent element. Trying to set width: 100% on the parent element li does not work, but setting width: 0 works. Right now: li{ flex: 0 0 33.333%; width: 0 } If the width is not set, li can be infinitely expanded by child nodes; therefore, p always has enough width to display all text in one line, and the truncation effect cannot be triggered. There is another way to test the effect: li{ flex: 0 0 33.333%; overflow: hidden; } The above two methods can achieve the desired effect, that is, when the flex value is set for li, it will dynamically obtain the remaining width of the parent container and will not be stretched by its own child elements.
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: Detailed explanation of the MySQL MVCC mechanism principle
>>: JavaScript to achieve elastic navigation effect
How to check the status of Linux firewall 1. Basi...
Shtml and asp are similar. In files named shtml, s...
Need to know how many days there are before an im...
Table of contents JS obtains the .txt file conten...
Duplicate form submission is the most common and ...
As the title says, otherwise when the page is revi...
Image Accelerator Sometimes it is difficult to pu...
What does Ctrl+c, Ctrl+d, Ctrl+z mean in Linux? C...
The parent node of the parent node, for example, t...
Today I recommend such an open source tool for ex...
Table of contents Preface 1. Routing lazy loading...
As more and more Docker images are used, there ne...
The previous article explained how to reset the M...
Execute the following command to report an error ...
1. Let's look at a table creation statement f...