Solve the problem that ElementUI custom CSS style does not take effect

Solve the problem that ElementUI custom CSS style does not take effect

For example, there is an input box

<el-input
        ref="mySearch"
        class="mySearch"
        size="small"
        placeholder="Please enter content"
        suffix-icon="el-icon-search"
        v-model="input1">
</el-input>

If no custom style is added, the input box will look like this

insert image description here

I hope so

insert image description here

Through the developer tools of Google Chrome, find the class name of the corresponding style.el .el-input__inner
But I found that the el-input tag in front of html was parsed into this, where mySearch was added by myself, so we can find the element of mySearch , and the sub-element class name that needs to be modified is .el-input__inner

insert image description here

insert image description here

If you select child elements through CSS selectors, you cannot apply it to the elements inside the child elements. The following uses stylus syntax. The following is an incorrect way of writing:

<style scoped lang="stylus" rel="stylessheet/stylus">
    .mySearch .el-input__inner
        border-radius 20px
</style>

How to make it work

Solution 1: You need to add a /deep/ in the middle to

<style scoped lang="stylus" rel="stylessheet/stylus">
    .mySearch /deep/ .el-input__inner
        border-radius 20px
</style>

Solution 2: Remove scoped . This method can achieve the desired effect but is not recommended!

In general, the reason why it does not work is that this scope causes the scope to not work on the internal sub-components. The final solution to the problem is to add /deep/ to make it work on the sub-components.

This is the end of this article about the solution to the problem of ElementUI custom CSS style not taking effect. For more relevant content about ElementUI style not taking effect, 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!

<<:  Detailed steps to deploy lnmp under Docker

>>:  How to remove the underline of a hyperlink using three simple examples

Recommend

Detailed explanation of how to use several timers in CocosCreator

1. setTimeOut Print abc after 3 seconds. Execute ...

Detailed example of using typescript to encapsulate axios in Vue3

This axios package is used in the vue3 demo. For ...

Detailed steps to install mysql in Win

This article shares the detailed steps of install...

How to Completely Clean Your Docker Data

Table of contents Prune regularly Mirror Eviction...

Vue implements adding watermark to uploaded pictures

This article shares the specific implementation c...

How to make a website look taller and more designed

“How to make a website look high-end? Or more des...

JavaScript to achieve mouse drag effect

This article shares the specific code of JavaScri...

Using JS timer to move elements

Use JS timer to make an element to make a method ...

Detailed explanation of Shell script control docker container startup order

1. Problems encountered In the process of distrib...

Solution to the inaccessibility of Tencent Cloud Server Tomcat port

I recently configured a server using Tencent Clou...

Continuous delivery using Jenkins and Docker under Docker

1. What is Continuous Delivery The software produ...

Difference and implementation of JavaScript anti-shake and throttling

Table of contents 1. Anti-shake 2. Throttling 3. ...

MySQL optimization solution: enable slow query log

Table of contents Preface Setting up slow query l...