如何在HTML / CSS中删除所选选项卡的边框?

我有用于创建水平选项卡栏的html和css,其中我有一些类和一个javascript函数,该函数根据特定选项卡的选择基本上更改选项卡:


function openPage(evt, cityName) {

  var i, tabcontent, tablinks;

  tabcontent = document.getElementsByClassName("tabcontent");

  for (i = 0; i < tabcontent.length; i++) {

    tabcontent[i].style.display = "none";

  }

  tablinks = document.getElementsByClassName("tablinks");

  for (i = 0; i < tablinks.length; i++) {

    tablinks[i].className = tablinks[i].className.replace(" active", "");

  }

  document.getElementById(cityName).style.display = "block";

  evt.currentTarget.className += " active";

}


// Get the element with id="defaultOpen" and click on it

document.getElementById("defaultOpen").click();

body {

  font-family: Arial;

}



/* Style the tab */


.tab {

  overflow: hidden;

  border: 1px solid #ccc;

  background-color: #f1f1f1;

}



/* Style the buttons inside the tab */


.tab button {

  background-color: inherit;

  float: left;

  border: none;

  outline: none;

  cursor: pointer;

  padding: 14px 16px;

  transition: 0.3s;

  font-size: 17px;

}



/* Change background color of buttons on hover */


.tab button:hover {

  background-color: #ddd;

}



/* Create an active/current tablink class */


.tab button.active {

  background-color: #FFFFFF;

  border-bottom-color: #FFFFFF;

}



/* Style the tab content */


.tabcontent {

  display: none;

  padding: 6px 12px;

  border: 1px solid #ccc;

  border-top: none;

}



/* Style the close button */


.topright {

  float: right;

  cursor: pointer;

  font-size: 28px;

}


.topright:hover {

  color: red;

}


当我运行它时,它工作正常,但是要删除的所选选项卡下方有一个下划线。有没有人有这个想法,如何在所选选项卡下删除它?


慕村225694
浏览 97回答 3
3回答

catspeake

唯一的变化是.tab {&nbsp; overflow: hidden;&nbsp; border: 1px solid #ccc;&nbsp; border-bottom-color: transparent;&nbsp; background-color: #f1f1f1;}/* Style the buttons inside the tab */.tab button {&nbsp; background-color: inherit;&nbsp; float: left;&nbsp; border-bottom: 1px solid #ccc;&nbsp; outline: none;&nbsp; cursor: pointer;&nbsp; padding: 14px 16px;&nbsp; transition: 0.3s;&nbsp; font-size: 17px;}

慕哥6287543

如果我错了,请告诉我,但你想看起来像这样吗?<html><head>&nbsp; <style>&nbsp; &nbsp; body {&nbsp; &nbsp; &nbsp; font-family: Arial;&nbsp; &nbsp; }&nbsp; &nbsp; /* Style the tab */&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; .tab {&nbsp; &nbsp; &nbsp; overflow: hidden;&nbsp; &nbsp; &nbsp; border: 1px solid #ccc;&nbsp; &nbsp; &nbsp; border-bottom: none;&nbsp; &nbsp; &nbsp; background-color: #f1f1f1;&nbsp; &nbsp; }&nbsp; &nbsp; /* Style the buttons inside the tab */&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; .tab button {&nbsp; &nbsp; &nbsp; background-color: inherit;&nbsp; &nbsp; &nbsp; float: left;&nbsp; &nbsp; &nbsp; border: none;&nbsp; &nbsp; &nbsp; outline: none;&nbsp; &nbsp; &nbsp; cursor: pointer;&nbsp; &nbsp; &nbsp; padding: 14px 16px;&nbsp; &nbsp; &nbsp; transition: 0.3s;&nbsp; &nbsp; &nbsp; font-size: 17px;&nbsp; &nbsp; }&nbsp; &nbsp; /* Change background color of buttons on hover */&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; .tab button:hover {&nbsp; &nbsp; &nbsp; background-color: #ddd;&nbsp; &nbsp; }&nbsp; &nbsp; /* Create an active/current tablink class */&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; .tab button.active {&nbsp; &nbsp; &nbsp; background-color: #FFFFFF;&nbsp; &nbsp; &nbsp; border-bottom-color: #FFFFFF;&nbsp; &nbsp; }&nbsp; &nbsp; /* Style the tab content */&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; .tabcontent {&nbsp; &nbsp; &nbsp; display: none;&nbsp; &nbsp; &nbsp; padding: 6px 12px;&nbsp; &nbsp; &nbsp; border: 1px solid #ccc;&nbsp; &nbsp; &nbsp; border-top: none;&nbsp; &nbsp; }&nbsp; &nbsp; /* Style the close button */&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; .topright {&nbsp; &nbsp; &nbsp; float: right;&nbsp; &nbsp; &nbsp; cursor: pointer;&nbsp; &nbsp; &nbsp; font-size: 28px;&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; .topright:hover {&nbsp; &nbsp; &nbsp; color: red;&nbsp; &nbsp; }&nbsp; </style></head><body>&nbsp; <h2>Tabs</h2>&nbsp; <p>Click on the x button in the top right corner to close the current tab:</p>&nbsp; <div class="tab">&nbsp; &nbsp; <button class="tablinks" onclick="openPage(event, 'Home')" id="defaultOpen">Home</button>&nbsp; &nbsp; <button class="tablinks" onclick="openPage(event, 'AboutUs')">AboutUs</button>&nbsp; &nbsp; <button class="tablinks" onclick="openPage(event, 'Careers')">Careers</button>&nbsp; </div>&nbsp; <div id="Home" class="tabcontent">&nbsp; &nbsp; <span onclick="this.parentElement.style.display='none'" class="topright">&times</span>&nbsp; &nbsp; <h3>Home</h3>&nbsp; &nbsp; <p>Home Page.</p>&nbsp; </div>&nbsp; <div id="AboutUs" class="tabcontent">&nbsp; &nbsp; <span onclick="this.parentElement.style.display='none'" class="topright">&times</span>&nbsp; &nbsp; <h3>AboutUs</h3>&nbsp; &nbsp; <p>AboutUs page.</p>&nbsp; </div>&nbsp; <div id="Careers" class="tabcontent">&nbsp; &nbsp; <span onclick="this.parentElement.style.display='none'" class="topright">&times</span>&nbsp; &nbsp; <h3>Careers</h3>&nbsp; &nbsp; <p>Careers Page.</p>&nbsp; </div>&nbsp; <script>&nbsp; &nbsp; function openPage(evt, cityName) {&nbsp; &nbsp; &nbsp; var i, tabcontent, tablinks;&nbsp; &nbsp; &nbsp; tabcontent = document.getElementsByClassName("tabcontent");&nbsp; &nbsp; &nbsp; for (i = 0; i < tabcontent.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; tabcontent[i].style.display = "none";&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; tablinks = document.getElementsByClassName("tablinks");&nbsp; &nbsp; &nbsp; for (i = 0; i < tablinks.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; tablinks[i].className = tablinks[i].className.replace(" active", "");&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; document.getElementById(cityName).style.display = "block";&nbsp; &nbsp; &nbsp; evt.currentTarget.className += " active";&nbsp; &nbsp; }&nbsp; &nbsp; // Get the element with id="defaultOpen" and click on it&nbsp; &nbsp; document.getElementById("defaultOpen").click();&nbsp; </script></body></html>

忽然笑

你可以像这样编写代码。elm.style.textDecoration&nbsp;=&nbsp;"none";
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript