html – 以百分比形式创建一个css三角形

前端之家收集整理的这篇文章主要介绍了html – 以百分比形式创建一个css三角形前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在顶部网站上创建一个正方形的div并流入三角形,

方形部分不是那么难,并且工作正常,但三角形部分有点难.
盒子需要改变大小与屏幕尺寸,在广场我这样做通过使用宽度和高度%,但我不能使用边框属性中的%符号

我现在的代码

HTML

  1. <div id="overV12" class="menuItem" onclick="scrollToT('#overons')" onmouSEOver="setHover('overV12')" onmouSEOut="setOldClass('overV12')"><div class="menuInner">Over V12</div></div>

CSS

  1. div.menuItem
  2. {
  3. height: 5.38%;
  4. width: 7.44%;
  5. position: fixed;
  6. background-color: rgb(239,239,239);
  7. cursor: pointer;
  8. z-index: 12;
  9. text-align: center;
  10. top: 4.3%;
  11. }
  12.  
  13. div.menuItemHover
  14. {
  15. height: 5.38%;
  16. width: 7.44%;
  17. position: fixed;
  18. cursor: pointer;
  19. z-index: 12;
  20. text-align: center;
  21. top: 4.3%;
  22. background-color: rgb(211,211,211);
  23. }
  24.  
  25. div.menuItemActive
  26. {
  27. height: 7.8%;
  28. width: 7.44%;
  29. position: fixed;
  30. cursor: pointer;
  31. z-index: 12;
  32. text-align: center;
  33. top: 4.3%;
  34. background-color: Black;
  35. color: White;
  36. }

JavaScript用于设置类:我这样做是因为我使用parralax库并且想要在某个高度上将“按钮”设置为“活动”

我希望有人可以帮我(也许还有其他人)解决这个问题

的jsfiddle
example
我的想法是,当在类menuItemActive上设置div时,它将有箭头,否则不是
仅当它设置为活动时才会这样

解决方法

这使用两个重叠的div来创建三角形和 this method以使事物流畅,同时保持纵横比.

Working Example

  1. .div1 {
  2. width:100%;
  3. height:100%;
  4. border: 1px solid red;
  5. position:absolute;
  6. z-index:2;
  7. }
  8. .div2 {
  9. width:70%;
  10. min-height:70%;
  11. transform:rotate(45deg);
  12. border:1px solid blue;
  13. position:absolute;
  14. left:15%;
  15. top:65%;
  16. z-index:1;
  17. }
  18. #container {
  19. display: inline-block;
  20. position: relative;
  21. width: 25%;
  22. }
  23. #dummy {
  24. padding-top: 100%;
  25. }
  26. #element {
  27. position: absolute;
  28. top: 0;
  29. bottom: 0;
  30. left: 0;
  31. right: 0;
  32. }

我没有背景就离开了它,所以你可以看到它是如何工作的.

猜你在找的HTML相关文章