css怎么把提示字体和图片显示在输入框中
可以使用CSS伪类来实现将提示字体和图片显示在输入框中。
- 将提示字体显示在输入框中:
input::placeholder {
font-size: 16px; /* 设置字体大小 */
color: #999; /* 设置字体颜色 */
}
- 将图片显示在输入框中:
input[type="text"] {
background-image: url('image.png'); /* 设置图片地址 */
background-repeat: no-repeat; /* 不重复显示 */
background-position: right center; /* 图片位置 */
padding-right: 25px; /* 预留图片位置 */
}
将上述两种方式结合起来,就可以同时将提示字体和图片显示在输入框中了:
input[type="text"] {
background-image: url('image.png'); /* 设置图片地址 */
background-repeat: no-repeat; /* 不重复显示 */
background-position: right center; /* 图片位置 */
padding-right: 25px; /* 预留图片位置 */
}
input[type="text"]::placeholder {
font-size: 16px; /* 设置字体大小 */
color: #999; /* 设置字体颜色 */
}
原文地址: http://www.cveoy.top/t/topic/bjS1 著作权归作者所有。请勿转载和采集!