简体   繁体   English

如何在CSS功能区菜单中制作右侧三角形?

[英]How to make right-side triangle in CSS ribbon menu?

As you'll see from this CodePen, I am nearly complete with this ribbon menu. 正如您将从此CodePen中看到的那样,该功能区菜单几乎已完成。 However, I cannot (for the life of me) figure out how to add the right-side triangle using CSS. 但是,(我一生中)我无法弄清楚如何使用CSS添加右侧三角形。 When I attempt to add the following code, it adds a big margin underneath the navigation menu: 当我尝试添加以下代码时,它在导航菜单下方添加了一个较大的空白:

#menu-nav:after {
 border-color: rgba(0, 0, 0, 0) #008000 rgba(0, 0, 0, 0) transparent;
 border-style: solid;
 border-width: 22px 25px 0px 0px;
 height: 0px;
 left: -10px;
 width: 0px;

} }

I know that those aren't the right border widths, but it should still show something more than a big bottom margin, right? 我知道那不是正确的边框宽度,但是它仍然应该显示比底边大的东西,对吗? My CodePen is here: CodePen 我的CodePen在这里: CodePen

The only thing I think may be causing this is something to do with how the blocks are positioned. 我认为唯一可能导致此问题的原因与块的放置方式有关。 I have the #menu-nav:before, #menu-nav:after positioned relative. 我有#menu-nav:before, #menu-nav:after相对。 I'm still a little new, so any help would be appreciated. 我还是有点新,所以任何帮助将不胜感激。

FYI - this is the original tutorial that I was following: http://css3.wikidot.com/blog:wrap-around-ribbons-with-css 仅供参考-这是我遵循的原始教程: http : //css3.wikidot.com/blog :wrap-around-ribbons-with- css

Simply the parent must have a width and position rule, and children position: absolute 只需父级必须具有宽度和位置规则,子级位置必须是绝对的

Here is a working example 这是一个有效的例子

EDIT: I checked your code, and you have visibility set to hidden, add visibility: visible to :after pseudo-element and it should work 编辑:我检查了您的代码,并且您将可见性设置为隐藏,添加可见性:可见到:after伪元素,它应该可以工作

Codepen: Ribbons with pseudo elements Codepen:带有伪元素的色带

.menu{
  width: 100%;
  height: 4em;
  background: #333;
  position: relative;
  padding: 0 2em;
  left: -2em;
}

.menu:after,
.menu:before {
  content: "";
  display: block;
  position: absolute;
  width: 0;
  height: 0;
  top: 100%;
  border-top: 1em solid #999;
  border-right: 1em solid transparent;
  border-left: 1em solid transparent;
  border-bottom: 1em solid transparent;
}
.menu:before {
  left: 0;
  border-right: 1em solid #999;
}
.menu:after {
  right: 0;
  border-left: 1em solid #999;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM