html – 使用CSS在导航栏中显示边框三角形

前端之家收集整理的这篇文章主要介绍了html – 使用CSS在导航栏中显示边框三角形前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个带有箭头的导航栏,该项目位于项目上方.这是我想要做的:

对于箭头,我使用了之前和之后的伪元素.以下是一些代码

  1. body {
  2. background: #FFFFFF;
  3. color: #FFFFFF;
  4. margin: 0px;
  5. padding: 0px;
  6. height: 100%;
  7. }
  8. .clear {
  9. clear: both;
  10. }
  11. .page-wrap {
  12. width: 980px;
  13. margin: 0px auto;
  14. height: 100%;
  15. }
  16. #main-menu {
  17. background: white;
  18. height: 55px;
  19. width: 100%;
  20. padding: 0px;
  21. margin: 0px;
  22. border-bottom: 1px solid black;
  23. }
  24. ul {
  25. font-family: Arial,Verdana;
  26. font-size: 18px;
  27. margin: 0;
  28. padding: 0;
  29. list-style: none;
  30. }
  31. ul li {
  32. display: block;
  33. position: relative;
  34. float: left;
  35. }
  36. li ul {
  37. display: none;
  38. }
  39. ul li a {
  40. display: block;
  41. text-decoration: none;
  42. color: black;
  43. padding: 0 9px 0 9px;
  44. background: white;
  45. margin-left: 1px;
  46. white-space: nowrap;
  47. line-height: 55px;
  48. font: 18px;
  49. font-family: Arial,Helvetica,sans-serif;
  50. outline: none;
  51. }
  52. ul li a:hover {
  53. color: black;
  54. }
  55. #menu a:hover:after {
  56. content: "";
  57. position: absolute;
  58. top: 40px;
  59. left: 50%;
  60. margin-left: -15px;
  61. width: 0px;
  62. height 0px;
  63. xxmargin: 0px auto;
  64. border-left: 15px solid transparent;
  65. border-right: 15px solid transparent;
  66. border-bottom: 15px solid black;
  67. }
  1. <header id="main-menu">
  2. <div class="page-wrap">
  3. <ul id="menu">
  4. <li><a href="#">Recommended</a></li>
  5. <li><a href="#">Recent</a></li>
  6. </ul>
  7. </div>
  8. </header>

Fiddle Link

由于边框颜色,箭头为黑色.如何只显示箭头的边框?

解决方法

只需在你添加的伪元素之前添加:after
  1. #menu a:hover:after {
  2. content: "";
  3. position: absolute;
  4. top: 41px;
  5. left: 50%;
  6. margin-left: -15px;
  7. width: 0px;
  8. height 0px;
  9. margin: 0px auto;
  10. border-left: 15px solid transparent;
  11. border-right: 15px solid transparent;
  12. border-bottom: 15px solid white;
  13. }
  14. #menu a:hover:before {
  15. content: "";
  16. position: absolute;
  17. top: 40px;
  18. left: 50%;
  19. margin-left: -15px;
  20. width: 0px;
  21. height 0px;
  22. margin: 0px auto;
  23. border-left: 15px solid transparent;
  24. border-right: 15px solid transparent;
  25. border-bottom: 15px solid black;
  26. }

我已经更新了你的笔请检查

http://codepen.io/anon/pen/vOxmGZ

猜你在找的HTML相关文章