我有一个 ASP.NET 文件上传控件。为文件上传控件的浏览按钮提供自定义样式我编写了以下代码:
label.choose:before {
background: #f07222 none repeat scroll 0 0;
border: 0 none;
border-radius: 5px;
color: #fff;
cursor: pointer;
font-weight: bold;
padding: 4.5px 12px;
text-transform: uppercase;
content: 'Browse';
position: absolute;
-webkit-margin-before: -2px;
-webkit-padding-start: 19px;
-webkit-padding-end: 19px;
}
<label class="choose">
<asp:FileUpload ID="FileUpload_DataFile" runat="server" />
</label>
它在 FireFox 和 Chrome 中工作正常。但在 IE 中,浏览按钮显示在输入文本的右侧。在 FF 和 Chrome 中,它显示在左侧。所以我的代码在 IE 中不起作用。 如果我添加
margin-left:141px;
仅适用于 IE 但如何仅对 IE 浏览器添加此属性? 我有 IE11。我想为 IE8 以上版本执行此操作。当我对此进行研发时,我发现了适用于 IE 的条件样式,但它在 IE9 以上版本中不起作用。
是否可以仅应用自定义样式文件上传按钮?如果可以,请给我代码示例?
有没有只为 IE 添加样式的解决方案? 或者有什么替代方法可以做到这一点?
最佳答案
我的问题得到了答案!!!
为IE设置css样式只写如下代码
_:-ms-input-placeholder, :root .choose:before {
margin-left: 141px;
}
这对 IE11 工作正常..!!
关于javascript - 仅针对 IE8 以上设置样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32946464/