gpt4 book ai didi

javascript - 创建 HTML 选项卡

转载 作者:行者123 更新时间:2023-12-03 02:59:20 26 4
gpt4 key购买 nike

我正在尝试创建 html 多个选项卡,如下图所示。 enter image description here

在下面的代码中,我创建了选项卡,但无法提供与如何在顶部剪切/和\等按钮相同的外观。也在标签按钮下方一行

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<style>
body {font-family: Arial;}

/* Style the tab */
div.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}

/* Style the buttons inside the tab */
div.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 */
div.tab button:hover {
background-color: #ddd;
}

/* Create an active/current tablink class */
div.tab button.active {
background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
</head>
<body>


<div class="tab">
<button class="tablinks" onclick="openCity(event, 'Filter')">Filter</button>
<button class="tablinks" onclick="openCity(event, 'Algorithm')">Algorithm</button>
<button class="tablinks" onclick="openCity(event, 'Settings')">Settings</button>
</div>

<div id="Filter" class="tabcontent" style="display:block">
<h3>Filter</h3>
<p>Filter is the capital</p>
</div>

<div id="Algorithm" class="tabcontent">
<h3>Algorithm</h3>
<p>Algorithm</p>
</div>

<div id="Settings" class="tabcontent">
<h3>Settings</h3>
<p>Settings Tab Content</p>
</div>

<script>
function openCity(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";
}
</script>

</body>
</html>

最佳答案

好吧,你可以用 clip-path 来做到这一点,主要问题是获取边框,因为 clip-path 不支持它们,但我们可以用小黑客。这是为您提供的示例,它应该可以为您提供如何执行此操作的良好开端:

.slanted {
width: 200px;
height: 40px;
background-color: black;
-webkit-clip-path: polygon(0 0, 94% 0, 100% 100%, 0% 100%);
clip-path: polygon(0 0, 94% 0, 100% 100%, 0% 100%);
position: relative;
}

.slanted:before {
content: '';
width: 198px;
height: 38px;
-webkit-clip-path: polygon(0 0, 94% 0, 100% 100%, 0% 100%);
clip-path: polygon(0 0, 94% 0, 100% 100%, 0% 100%);
background: red;
display: block;
position: absolute;
top: 1px;
left: 1px;
}
<div class="slanted"></div>

关于javascript - 创建 HTML 选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47474942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com