Detailed explanation of how to modify the style of el-select: popper-append-to-body and popper-class

Detailed explanation of how to modify the style of el-select: popper-append-to-body and popper-class

How to modify the style of the el-select component provided by elementUI

There are many solutions to this problem on the Internet:

1. Find the class name of the drop-down box and write a全局樣式覆蓋it.
2. Modify the style of .el-select-dropdown__item
3. Modify the style through popper-class provided by the official website

However, the above method does not hit the point. Overriding the global style is definitely not user-friendly, and modifying the style and adding classes do not work either. So, I looked at the style of the drop-down box. It was not in el-select , but placed on the outermost layer, as shown below:

Then I went to the official website to see if there is a property to control it, and sure enough, there is such a person popper-append-to-body :

The default value is true , change it to false to make it work

HTML

<el-select
    :popper-append-to-body="false"
    v-model="taskType"
    placeholder="Please select"
    size="mini"
    class="select-style"
    popper-class="select-popper"
  >
    <el-option
      v-for="(item,index) in taskTypes"
      :key="index"
      :value="item.value"
      :label="item.label"
    ></el-option>
  </el-select>

The code structure is as follows:

In fact, this only changes the style inside the drop-down box. The style of the input box also needs to be modified by modifying the .el-input__inner style:

CSS

.select-style {
    width: 3rem;
    margin-right: 0.36rem;
    /deep/.el-input__inner {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
      border: 1px solid #a1a3ad;
      border-left-width: 0;
      background-color: rgba(0, 0, 0, 0.8);
      font-family: PingFangSC-Regular;
      font-size: 0.28rem;
      color: rgba(255, 255, 255, 0.6);
    }
  }

Finally, attach the style of .select-popper :

/deep/.select-popper {
    background-color: $item-bg-color;
    border-radius: 0.08rem;
    border: solid 0.02rem #1c395d;
    font-family: PingFangSC-Regular;
    .el-select-dropdown__item.selected {
      font-family: PingFangSC-Regular;
      font-size: 0.28rem;
      color: rgba(74, 141, 253, 1);
    }
    li {
      color: #fff;
      background: transparent;
      color: #fff;
      font-size: 0.28rem;
    }
    .el-select-dropdown__item:hover,
    .el-select-dropdown__item.hover {
      background-color: rgba(110, 147, 206, 0.2);
      margin-right: 1px;
    }
    .popper__arrow::after {
      border-bottom-color: $item-bg-color;
    }
    .popper__arrow {
      border-bottom-color: $item-bg-color;
    }
    .el-select-dropdown__empty {
      padding: 0.2rem;
      font-size: 0.28rem;
    }
  }

Summarize

Key point: :popper-append-to-body="false" , then add popper-class to modify the style.

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.

<<:  Professional and non-professional web design

>>:  JavaScript Basics: Immediate Execution Function

Recommend

Best Practices for Sharing React Code

When any project develops to a certain complexity...

Detailed explanation of using Nginx reverse proxy to solve cross-domain problems

question In the previous article about cross-doma...

Linux system calls for operating files

Table of contents 1. Open the file Parameter Intr...

How to use Spark and Scala to analyze Apache access logs

Install First you need to install Java and Scala,...

Getting Started Tutorial on Animating SVG Path Strokes Using CSS3

Without relying on JavaScript, pure CSS is used t...

A brief discussion on MySQL B-tree index and index optimization summary

MySQL's MyISAM and InnoDB engines both use B+...

Six ways to reduce the size of Docker images

Since I started working on Vulhub in 2017, I have...

Getting Started with Vue 3.0 Custom Directives

Table of contents 1. Custom instructions 1. Regis...

Pure CSS3 code to implement a running clock

Operation effectCode Implementation html <div ...

Two common solutions to html text overflow display ellipsis characters

Method 1: Use CSS overflow omission to solve The ...

MySQL5.7 single instance self-starting service configuration process

1.MySQL version [root@clq system]# mysql -v Welco...

Detailed steps for deploying Tomcat server based on IDEA

Table of contents Introduction Step 1 Step 2: Cre...

How to understand the difference between computed and watch in Vue

Table of contents Overview computed watch monitor...

Detailed graphic and text instructions for installing MySQL 5.7.20 on Mac OS

Installing MySQL 5.7 from TAR.GZ on Mac OS X Comp...