html - 为什么IE对border-style应用不透明度: dotted?

标签 html css internet-explorer border

标题说明了一切,我刚刚发现 IE (9 - 11) 会自动将大约 50% 的不透明度应用到任何带有 border-style: dotted 的元素的边框。

最奇怪的是,它只发生在 dotted 上,特别是 soliddashed 都可以。

大家可以自己测试:http://jsfiddle.net/ptv74f4q/1/

有什么想法吗?

最佳答案

这似乎是由于 IE 消除了虚线边框的锯齿。如果您使 border-width 大于 1px(例如 5px),边框将再次显示为白色。

解决这个问题的一种方法是在顶部覆盖一些具有相同虚线边框的伪元素以抵消不透明度:

div {
    width: 200px;
    height: 200px;
    background: #000;
}
span {
    transform: rotate(0deg);
    display: inline-block;
    width: 180px;
    height: 85px;
    line-height: 85px;
    text-align: center;
    margin: 8px 8px 0 8px;
    border: #fff 1px solid;
    color: #fff;
    position: relative;
}
span.dotted {
    border-style: dotted;
}
span.dotted::before, span.dotted::after {    
    border: #fff 1px dotted;
    content: "";
    height: 100%;
    left: -1px;
    position: absolute;
    top: -1px;
    width: 100%;
}
<div>
    <span>I'm with normal border</span>
    <span class="dotted">I'm with dotted border</span>
</div>

JS fiddle : http://jsfiddle.net/oyrbLyjc/1/

替代方法

或者,您可以尝试使用 border-image。有在线工具(例如 https://developer.mozilla.org/en-US/docs/Web/CSS/Tools/Border-image_generator )可以帮助您使用此方法生成类似的边框。

关于html - 为什么IE对border-style应用不透明度: dotted?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27231400/

相关文章:

html - 仅限于 CSS-2.1,当边框折叠时,我能否确保表格中的一个边框显示另一个边框的 'on top'

javascript - 在 Javascript 中禁用/不可点击 HTML 按钮

php - 如何在 laravel 上将字符串从 jquery 翻译为blade

php - 如何写... 5 个字符后

javascript - 单击 <a href> 时的 Bootstrap flip div 在移动设备上不起作用

javascript - JavaScript 中的 IF IE 条件注释?

javascript - 将文件上传到 HTML 表单并提交之间会发生什么?

javascript - 正确缩放图像但适合 div

html - 带有 colspan 集的 Internet Explorer 8 表格单元格宽度错误

html - 剪辑路径 SVG 多边形 Internet Explorer