将向下箭头添加到选项卡菜单

时间:2016-11-04 20:35:09

标签: jquery html css html5

目前,我正在处理一个简单的标签菜单,并希望在标签处于活动状态时显示向下箭头。这是我正在使用的当前代码。我在jQuery中尝试过一些东西,但没有运气。 CSS似乎是实现这一目标的最佳方式。我对么?你会如何做到这一点?

顺便说一句,请查看完整页面视图中的代码以获得更好的样式。



.tab_menu {
  margin: 40px 30px 0 30px;
}
ul.tab {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #ccc;
  background-color: rgba(68, 170, 255, 0.1);
}
/* Float the list items side by side */

ul.tab li {
  border-left: 1px solid #ccc;
  float: left;
  margin-bottom: 0;
  margin-left: 0;
}
/* Style the links inside the list items */

ul.tab li a {
  display: inline-block;
  color: black;
  /* text-align: center; */
  padding: 14px 9px 14px 9px;
  text-decoration: none;
  transition: 0.3s;
  font-size: 17px;
  margin: 0;
  width: 150px;
  height: 35px;
  text-align: center;
}
/* Change background color of links on hover */

ul.tab li a:hover {
  background-color: rgba(68, 170, 255, 0.5);
}
/* Create an active/current tablink class */

ul.tab li a:focus,
.active {
  background-color: rgba(68, 170, 255, 0.9);
}
/* Style the tab content */

.tabcontent {
  display: none;
  padding: 25px 12px;
  border: 1px solid #ccc;
  border-top: none;
}
.tab_menu a {
  text-align: center;
}
.triangle-bottom {
  border-top: solid 20px #54b1ff;
  border-left: solid 25px transparent;
  border-right: solid 25px transparent;
  width: 0;
  height: 0;
  position: absolute;
  margin-left: 168px;

<div class="tab_menu">
  <ul class="tab">
    <li><a href="javascript:void(0)" class="active tablinks" onclick="openContent(event, 'coverage');" id="defaultOpen">Our Coverage</a>
      <div class="triangle-bottom"></div>
    </li>
    <li><a href="javascript:void(0)" class="tablinks" onclick="openContent(event, 'claims')">Common Claims</a>
    </li>
    <li><a href="javascript:void(0)" class="tablinks" onclick="openContent(event, 'bwc')">Buy With Confidence</a>
    </li>
    <li><a href="javascript:void(0)" class="tablinks" onclick="openContent(event, 'faq')">Frequently Asked Questions</a>
    </li>
  </ul>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

从您提供的代码中,只需调整左边距即可完成工作

.triangle-bottom {
   margin-left: 119px;
}

.tab_menu {
  margin: 40px 30px 0 30px;
}
ul.tab {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #ccc;
  background-color: rgba(68, 170, 255, 0.1);
}
/* Float the list items side by side */

ul.tab li {
  border-left: 1px solid #ccc;
  float: left;
  margin-bottom: 0;
  margin-left: 0;
}
/* Style the links inside the list items */

ul.tab li a {
  display: inline-block;
  color: black;
  /* text-align: center; */
  padding: 14px 9px 14px 9px;
  text-decoration: none;
  transition: 0.3s;
  font-size: 17px;
  margin: 0;
  width: 150px;
  height: 35px;
  text-align: center;
}
/* Change background color of links on hover */

ul.tab li a:hover {
  background-color: rgba(68, 170, 255, 0.5);
}
/* Create an active/current tablink class */

ul.tab li a:focus,
.active {
  background-color: rgba(68, 170, 255, 0.9);
}
/* Style the tab content */

.tabcontent {
  display: none;
  padding: 25px 12px;
  border: 1px solid #ccc;
  border-top: none;
}
.tab_menu a {
  text-align: center;
}
.triangle-bottom {
  border-top: solid 20px #54b1ff;
  border-left: solid 25px transparent;
  border-right: solid 25px transparent;
  width: 0;
  height: 0;
  position: absolute;
  margin-left: 119px;
  }
<div class="tab_menu">
  <ul class="tab">
    <li><a href="javascript:void(0)" class="active tablinks" onclick="openContent(event, 'coverage');" id="defaultOpen">Our Coverage</a>
      <div class="triangle-bottom"></div>
    </li>
    <li><a href="javascript:void(0)" class="tablinks" onclick="openContent(event, 'claims')">Common Claims</a>
    </li>
    <li><a href="javascript:void(0)" class="tablinks" onclick="openContent(event, 'bwc')">Buy With Confidence</a>
    </li>
    <li><a href="javascript:void(0)" class="tablinks" onclick="openContent(event, 'faq')">Frequently Asked Questions</a>
    </li>
  </ul>
</div>