我正在尝试来自http://www.smashingmagazine.com/2015/05/creating-responsive-shapes-with-clip-path/的 CSS Clip Path ,我遇到了这个疯狂的错误。简而言之,该代码适用于 CodePen 和 JSFiddle,但无法在我的本地/应用程序上运行。
这是我试图提出的多边形的代码。首先是CSS:
nav {
position: fixed;
bottom: 0;
background: #BE0F16;
color: #fff;
width: 100%;
padding: 2rem 1rem;
text-align: right;
-webkit-clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 50%);
clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 50%);
-webkit-clip-path: url("#clip-shape");
clip-path: url("#clip-shape");
}
nav .next-chapter {
color: #fff;
padding-left: 1rem;
}
这是相关的HTML:
<!DOCTYPE html>
<html>
<head>
<title>Something</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<link href="css.css" rel="stylesheet" />
</head>
<body>
<nav>
<a class="menu"><i title="Menu" class="fa fa-bars"></i><h1 class="visuallyhidden">Menu</h1></a>
<a class="next-chapter" href="/<%=next%>"><i title="Next Chapter" class="fa fa-hand-o-right"></i><span class="visuallyhidden">Next Chapter</span></a>
<a id="comment" href="http://twitter.com/?status=@uebyn"></a>
</nav>
<svg width="0" height="0">
<defs>
<clipPath id="clip-shape" clipPathUnits="objectBoundingBox">
<polygon points="0 0, 0 1, 1 1, 1 .5" />
</clipPath>
</defs>
</svg>
<script src="script.js"></script>
</body>
</html>
当我打开 index.html(上面的 HTML)时,它显示了一个矩形而不是我期望的多边形。然而,我遵循了文章中所述的确切说明。
然后我将代码复制到同一浏览器上的CodePen ( http://codepen.io/anon/pen/JdwrQw ) 和 JSFiddle ( http://jsfiddle.net/yk95wxmL/ ),它就可以工作了。
我一生都无法理解这一点。Firefox 理解并在 CodePen 和 JSFiddle 上的相同代码上剪辑路径,但不是在我的 HTML 上?可以肯定的是,我将整个 HTML 复制到 Codepen,并且 css 剪辑路径有效。这完全超出了我的范围。如果有人能提出一个可能显而易见但我不知何故错过的建议,我将不胜感激。