Flex layout realizes left text overflow and omits right text adaptation

Flex layout realizes left text overflow and omits right text adaptation

I want to achieve a situation where the width of the text on the left can be automatically adjusted according to the length of the text. When one line cannot be displayed, the space for the text on the right will not be squeezed, and the text on the left will overflow and be omitted. Similarly, when the text on the right becomes longer, the text on the right is fully displayed, and the text on the left is squeezed and overflows, resulting in the effect of being omitted. What I said may not be very clear, let's take a look at the effect picture.

1. The width of the text on the right is the same as the text on the right, and the left side occupies all the remaining space by default.

2. The width of the text on the right is the same as 1. The text on the left is very long and overflows.

3. The text on the left is the same as 2, but the text on the right has two "right" added to it.

Below is the style:

.footer {
  width: 300px;
  height: 20px;
  display: flex;
  overflow: hidden;
}
.left {
  background: #3cc8b4;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 50px;
}
.right {
  background: #9bc;
  max-width: 250px;
}
.right-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

<div class="footer">
   <div class="left">
     leftleftleftleftleftleftleftleftleftleftleftleft
  </div>
  <div class="right">
    <div class="right-ellipsis">
      rightrightrightrightrightrightrightright
    </div>
  </div>
</div>

The code adds max-width, min-width and a div called right-ellipsis. To achieve the following effects:

We can achieve different effects according to our needs. Summary of design requirements: The width on the left side grows automatically, the width on the right side grows automatically and cannot overflow or be omitted. When the length of the left text exceeds the limit, the left text overflows and is omitted. The effect is as follows:

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.

<<:  Three ways to communicate between React components (simple and easy to use)

>>:  The difference between docker run and start

Recommend

Reasons and solutions for MySQL failing to create foreign keys

When associating two tables, a foreign key could ...

In-depth study of vue2.x--Explanation of the h function

Table of contents Solution, Summarize: vue projec...

Implementation script for scheduled database backup in Linux

Table of contents Scenario: The server database n...

Summary of methods for inserting videos into HTML pages

Now if you want to use the video tag in a page, y...

Using JS to implement binary tree traversal algorithm example code

Table of contents Preface 1. Binary Tree 1.1. Tra...

Detailed steps to install python3.7 on CentOS6.5

1. Download Python 3 wget https://www.python.org/...

Implementation of Nginx operation response header information

Prerequisite: You need to compile the ngx_http_he...

Detailed steps for Python script self-start and scheduled start under Linux

1. Python automatically runs at startup Suppose t...

Tutorial on logging into MySQL after installing Mysql 5.7.17

The installation of mysql-5.7.17 is introduced be...

Example of how to configure nginx to implement SSL

Environmental Description Server system: Ubuntu 1...

How to configure NAS on Windows Server 2019

Preface This tutorial installs the latest version...

Implementing Priority Queue in JavaScript

Table of contents 1. Introduction to priority que...

Mysql specifies the date range extraction method

In the process of database operation, it is inevi...