html - 在带有颜色的 div 前面放置一个输入,并保持输入白色背景和图像

标签 html css

我有一个位于 div 内部的输入。当我设置 div 背景颜色时,它也会更改输入背景颜色。输入有背景图像,所以我不能简单地为输入设置背景颜色。

因此,我需要一种方法来更改 div 内部输入的背景颜色,同时保留 div 的背景图像。

CSS:

#searchDiv{
    background:#606060;
    position:relative;
}
#topSearch{
    font: 40px Segoe UI Light;
    width:94%;
    height:60px;
    text-indent: 62px;
    background:white;
    background: url('search_icon.png');
    background-repeat: no-repeat;
    background-position: left; 
  background-size: 60px;
  margin: 10px 3% 10px 3%;
}

HTML:

<div id="searchDiv">
    <input type="search" id="topSearch"></input>    
</div>

最佳答案

像这样更改输入的样式:

    #topSearch {
    font: 40px Segoe UI Light;;
    width:94%;
    height:60px;
    text-indent: 62px;
    background-color:white;
    background-image: url('search_icon.png');
    background-repeat: no-repeat;
    background-position: left; 
    background-size: 60px;
    margin: 10px 3% 10px 3%;
}

关于html - 在带有颜色的 div 前面放置一个输入,并保持输入白色背景和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29526758/

相关文章:

javascript - 重定向到父窗口

javascript - 使用 Canvas 外解决方案时,如何使固定标题与 body 的其余部分保持一致?

html - 使用 css 替换具有不一致类的表行颜色的方法

jquery - 如何通过JQuery修改div元素的CSS属性(高度宽度)?

html - 当窗口变小时保持图像比例相同

html - 下拉菜单

html - 100% 到底是做什么的? (多案例研究)

javascript - 从中断的地方重新启动 CSS3 动画?

html - flex 容器的背景图像

html - 如何在 Joomla 2.5 模板中垂直对齐这两列?