【问题标题】:Transform skew causes 0.5px vertical shift in IE变换倾斜导致 IE 中的 0.5px 垂直偏移
【发布时间】:2016-06-08 22:04:42
【问题描述】:

我正在制作一个右侧倾斜的形状。

代码如下:

h2 {
  display: inline-block;
  position: relative;
  text-transform: uppercase;
  background: #2b4450;
  color: white;
  font: bold 16.67px'Raleway', sans-serif;
  padding: 0 35px;
  height: 35px;
  line-height: 35px;
  cursor: pointer;
}
h2:before {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 34px;
  transform-origin: right top;
  transform: skew(30deg) translate3d(0, 0, 0);
  background: inherit;
}
<h2>ALL CAMPAIGNS</h2>
<br/>
<br/>
<h2>ALL CAMPAIGNS</h2>
<br/>
<br/>
<h2>ALL CAMPAIGNS</h2>
<br/>
<br/>
<h2>ALL CAMPAIGNS</h2>

在 Chrome 和 Firefox 中看起来不错,但在 IE 中不行。在 IE 中,伪元素向上移动大约 0.5px,有时向下移动 0.5px,这就是它的外观:

JSFiddle demo

有什么建议吗?

【问题讨论】:

  • 可以选择边框吗?喜欢jsfiddle.net/3nmha5sf/5。顺便提一句;哪个版本的IE?因为我在 IE11 中看不到这种失真。
  • @Seika85 您的示例看起来不错,但在这种情况下,伪元素会提供额外的不可见可点击区域。我使用 IE11 (11.0.9600.17498)。我想我有 2 个选项,使用图像或保持原样,希望这种 IE 行为很少被发现:)
  • 你在这里:jsfiddle.net/3nmha5sf/6 没有额外的可点击区域。我会把它放在答案中......
  • 或者更简单:jsfiddle.net/3nmha5sf/9

标签: css internet-explorer css-transforms


【解决方案1】:

如果可以选择边框:https://jsfiddle.net/3nmha5sf/9/

HTML

<h2>ALL CAMPAIGNS</h2>
<br/>
<br/>
<h2>ALL CAMPAIGNS</h2>
<br/>
<br/>
<h2>ALL CAMPAIGNS</h2>
<br/>
<br/>
<h2>ALL CAMPAIGNS</h2>

SCSS

h2 {
    display: inline-block;
    position: relative;
    text-transform: uppercase;
    background: #2b4450;
    color: white;
    font: bold 16.67px 'Raleway', sans-serif;
    padding: 0 35px;
    height: 35px;
    line-height: 35px;
    cursor: pointer;

    &:after {
        content: '';
        position: absolute;
        right: -20px;
        bottom: 0;
        width: 0;
        background: none;
        height: 0;
        border: solid transparent;
        border-bottom-color: #2b4450;
        border-width: 0 20px 35px;
    }   
}

【讨论】:

  • 在我的 IE 中看起来不错,谢谢 :) 如果有其他方法,我会考虑不使用转换
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-21
  • 2011-07-07
  • 1970-01-01
相关资源
最近更新 更多