css 中background 设置文本框背景图 的方法

Glory ·
更新时间:2024-09-20
· 876 次阅读

background 属性的作用是给元素设置背景,它是一个复合属性,常用的子属性如下:

•background-color 指定元素的背景颜色。

 •background-image 指定元素的背景图像。

•background-position 指定背景图像的位置,在复合属性中与 size 二选一。

•background-size 指定背景图片的尺寸,在复合属性中与 position 二选一。

•background-repeat 指定如何重复背景图像。

多数时候,我们都是给 div 等区块元素设置背景,其实还可以通过 background 属性来给文本框设置背景色和背景图片。呈现效果如下:

实现代码如下:

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>background 设置文本框背景图</title> <style> .search { width: 600px; height: 40px; padding: 5px; border: 1px solid #666666; background-color: #FAF9DE; background-image: url(images/search.png); background-position: center right; background-size: 50px 50px; background-repeat: no-repeat; } .remark { width: 600px; height: 200px; padding: 5px; margin-top: 10px; border: 1px solid #666666; background: url(images/belle.jpg) center center no-repeat; } </style> </head> <body> <input class="search" type="text" placeholder="请输入查询关键词"><br> <textarea class="remark" placeholder="请填写备注信息"></textarea> </body> </html>

更多 background 属性的知识可参考:

•CSS background 属性

•CSS background 属性

总结

以上所述是小编给大家介绍的css 中background 设置文本框背景图 的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对软件开发网网站的支持!如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!



方法 背景图 文本框 background CSS

需要 登录 后方可回复, 如果你还没有账号请 注册新账号