2017-08-09 70 views
1

我有这个代码在Chrome和Internet Explorer中完美工作。但是每当我结合下面的CSS样式,它只能在Internet Explorer中工作,而不能在Chrome中工作。占位符风格不适用于铬?

有没有人关于这种奇特的行为?

.searchBar{ 
 
\t height:50px; 
 
\t width:200px; 
 
\t background-color:#9a005f; 
 
\t color:#fff; 
 
} 
 
.searchBar:focus{ 
 
\t background-color:#9a445f; 
 
} 
 
.searchBar::-webkit-input-placeholder{ 
 
color:#fff; 
 
} 
 
.searchBar::-ms-input-placeholder{ 
 
\t color:#fff; 
 
}
<input type="text" class="searchBar" placeholder="Search for..."/>

编辑: 下面是不是在我的铬工作,但在IE工作。

.searchBar{ 
 
\t height:50px; 
 
\t width:200px; 
 
\t background-color:#9a005f; 
 
\t color:#fff; 
 
} 
 
.searchBar:focus{ 
 
\t background-color:#9a445f; 
 
} 
 
.searchBar::-webkit-input-placeholder, 
 
.searchBar::-ms-input-placeholder{ 
 
    color:#fff; 
 
}
<input type="text" class="searchBar" placeholder="Search for..."/>

+0

Chrome多年来一直不是webkit浏览器,现在大多数供应商前缀都在标志后面,所以我并不感到惊讶,您所做的不起作用。 – Rob

+0

那么为什么它仅适用于'.searchBar :: - webkit-input-placeholder'? – Pratyush

+0

您的代码片段适用于我的Chrome。 – Terry

回答

3

我已经做了一些网络上搜索,我发现了我认为是the answer你的问题。

请勿混用供应商前缀选择器(-moz,-webkit,-ms,...)。 Chrome例如不会理解“-moz-”,然后忽略整个 选择器。