How to solve the problem that the transparency of the input box affects the transparency of the placeholder

Insert image description here
There is a requirement to write an input box as shown above.
The first thing that comes to mind is to adjust the transparency of the input

<div class="inputDiv">
      <img src="./images/search.png" />
      <input type="text" class="myInput" placeholder="请输入标题关键字"/>
</div>
.inputDiv{
    
    
    border-radius: 16px;
    height:3.2rem;
    width:32rem;
    margin-top:0.7rem;
    display: flex;
    align-items: center;
    padding-left:0.9rem;
}
.myInput{
    
    
    height:3.2rem;
    opacity: 0.24;
    padding:0;
    padding-inline:0;
    padding-block:0;
    border-width:0;
    width:27.5rem;
    font-size: 1.4rem;
    color: #FFFFFF ;
}
.myInput::placeholder {
    
    
    color: #FFD6B5 ;
    font-size: 1.4rem;
    line-height: 3.2rem;
    text-align: center;
}

Insert image description here
In this way, you will find that the transparency of the placeholder will also be affected by the transparency of the input box.

If you implement transparency in background-color, you won’t have this problem
Final implementation plan

.inputDiv{
    
    
    background-color: rgba(255, 255, 255, 0.24);
    border-radius: 16px;
    height:3.2rem;
    width:32rem;
    margin-top:0.7rem;
    display: flex;
    align-items: center;
    padding-left:0.9rem;
}
.inputDiv img {
    
    
    width:1.8rem;
    height:1.8rem;
}
.myInput{
    
    
    height:3.2rem;
    background-color: rgba(255, 255, 255, 0);
    padding:0;
    padding-inline:0;
    padding-block:0;
    border-width:0;
    width:27.5rem;
    font-size: 1.4rem;
    color: #FFFFFF ;
}
.myInput::placeholder {
    
    
    color: #FFD6B5 ;
    font-size: 1.4rem;
    line-height: 3.2rem;
    text-align: center;
}

Guess you like

Origin blog.csdn.net/qq_41867900/article/details/134892441