【问题标题】:want to give placeholder 2 different colors想给占位符 2 种不同的颜色
【发布时间】:2015-11-25 08:35:37
【问题描述】:

有什么技巧可以让占位符变成 2 种不同的颜色, 这是代码

<input type="text" 
       class="form-control setting-form" 
       id="inputDefault2" 
       placeholder="http://blabbr.im/#itsmynewawesomechat">

我想给 "blabbr.im/" 颜色 rgba(255,255,255,0.3) 和“#itsmynewawesomechat”颜色 rgba(255,255,255,1)...

【问题讨论】:

  • 或者有什么方法可以将占位符和值用于相同的输入...比如占位符(不可编辑)和值(可编辑)...

标签: html css placeholder


【解决方案1】:

没有办法用两种不同的颜色来设置占位符的样式。作为替代方案,您可以同时设置 &lt;label&gt;&lt;input&gt; 的样式,使其看起来像单个 &lt;input&gt;(或任何其他标签,如 &lt;span&gt;)。

label, input {
    background-color: #4679BD;
    border: 1px solid #567890;
    float: left;
    font-family: sans-serif;
    font-size: 14px;
    line-height: 1.4;
    padding: 2px 5px;
}

label {
    border-radius: 2px 0 0 2px;
    border-right: 0;
    color: rgba(255,255,255,0.3);
    padding-right: 0;
}

input {
    border-radius: 0 2px 2px 0;
    border-left: 0;
}

::-webkit-input-placeholder {
    color: rgba(255,255,255,1);
}

:-moz-placeholder {
    color: rgba(255,255,255,1);
}

::-moz-placeholder {
    color: rgba(255,255,255,1);
}

:-ms-input-placeholder {  
    color: rgba(255,255,255,1);
}
<div>
    <label for="hashtag">http://blabbr.im/</label>
    <input id="hashtag" type="text" placeholder="#itsmynewawesomechat"/>
</div>

【讨论】:

    【解决方案2】:

    要更改您可以使用的占位符样式:

        ::-webkit-input-placeholder {
       color: red;
    }
    
    :-moz-placeholder { /* Firefox 18- */
       color: red;  
    }
    
    ::-moz-placeholder {  /* Firefox 19+ */
       color: red;  
    }
    
    :-ms-input-placeholder {  
       color: red;  
    }
    

    您可以使用 id 或 nth-child() 来定位您的第二个输入

    【讨论】:

    • 不,我想给同一个占位符不同的颜色...我想给 "blabbr.im/" 颜色 rgba(255,255,255,0.3) 和 "#itsmynewawesomechat" 颜色 rgba(255,255,255, 1)...
    猜你喜欢
    • 2012-11-08
    • 2016-08-20
    • 2023-03-10
    • 2014-07-27
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    相关资源
    最近更新 更多