Example code for implementing a three-column layout with CSS, where the middle column is adaptive and changes width with text size

Example code for implementing a three-column layout with CSS, where the middle column is adaptive and changes width with text size

The questions encountered in Baidu interviews need to achieve the following layout effects

The size of the purple column in the middle will widen/narrow with the amount of fonts, and the extra text will be automatically omitted as [...]. The green column on the right should be closely connected to the purple column. The main operations for the purple column are:

1.flex: 0 1 auto (adaptive)

2.text-overflow:ellipsis; (automatically omit text)

overflow:hidden;

white-space: nowrap;

The complete code is as follows

// CSS part.container {
  display: flex;
}
.pic {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background-color: pink;
}
.name {
  flex:0 1 auto;
  height: 100px;
  background-color: purple;
  text-overflow:ellipsis;
  overflow:hidden;
  white-space: nowrap;
}
.tag {
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  background-color: seagreen;
}
// HTML part <div class="container">
    <div class="pic"></div>
    <div class="name">
        zhasansndfdkfnald
    </div>
    <div class="tag">Designer</div>
</div>

Summarize

This concludes this article about how to use CSS to implement a three-column layout with the middle column adaptive and changing width with text size. For more relevant CSS three-column layout content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Util module in node.js tutorial example detailed explanation

>>:  Use iframe to submit form without refreshing the page

Recommend

Analysis of the principle and creation method of Mysql temporary table

This article mainly introduces the principle and ...

Usage and difference of Js module packaging exports require import

Table of contents 1. Commonjs exports and require...

How to modify the time in centos virtual machine

The one above shows the system time, and the one ...

Using loops in awk

Let's learn about different types of loops th...

7 useful new TypeScript features

Table of contents 1. Optional Chaining 2. Null va...

WeChat Mini Program Lottery Number Generator

This article shares the specific code of the WeCh...

css3 animation ball rolling js control animation pause

CSS3 can create animations, which can replace man...

Ansible automated operation and maintenance deployment method for Linux system

Ansible is a new automated operation and maintena...

Detailed explanation of Linux one-line command to process batch files

Preface The best method may not be the one you ca...

How to elegantly back up MySQL account information

Preface: I recently encountered the problem of in...

Talk about the 8 user instincts behind user experience in design

Editor's note: This article is contributed by...

Install redis and MySQL on CentOS

1|0MySQL (MariaDB) 1|11. Description MariaDB data...

How InnoDB implements serialization isolation level

Serialization implementation InnoDB implements se...