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

Tomcat first deployment web project process diagram

Put your own web project in the webapps directory...

Introducing ECharts into the Vue project

Table of contents 1. Installation 2. Introduction...

Causes and solutions to the garbled character set problem in MySQL database

Preface Sometimes when we view database data, we ...

Detailed explanation of json file writing format

Table of contents What is JSON Why this technolog...

10 SQL statement optimization techniques to improve MYSQL query efficiency

The execution efficiency of MySQL database has a ...

CSS achieves footer "bottom absorption" effect

We often encounter this problem: how to use CSS t...

Mysql uses insert to insert multiple records to add data in batches

If you want to insert 5 records into table1, the ...

Building a Redis cluster on Docker

Table of contents 1. Pull the image 2. Create a R...

After docker run, the status is always Exited

add -it docker run -it -name test -d nginx:latest...

Detailed explanation of common template commands in docker-compose.yml files

Note: When writing the docker-compose.yml file, a...

5 super useful open source Docker tools highly recommended

Introduction The Docker community has created man...

Implementation of Docker packaging image and configuration modification

I have encountered many problems in learning Dock...

Steps to export the fields and related attributes of MySQL tables

Need to export the fields and properties of the t...