gpt4 book ai didi

javascript - 如何使两个按钮像切换按钮一样

转载 作者:太空宇宙 更新时间:2023-11-04 06:51:03 25 4
gpt4 key购买 nike

我有两个按钮相互重叠,看起来像 overlapped buttons

enter image description here

我把它做成了两个带有我在下面提供的 CSS 的按钮...

.tab {
overflow: hidden;
}

.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
border-radius: 30px;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
border:1px solid #cccc;
color: #676767;
&.active {
color:#ffffff ;
background-color: #009bdf;
}
}
 <div class="tab"  style="width: 100%;">
<button class="tablinks" [class.active]="activeTab=='btn1'" (click)="clickType('btn1')" style="width: 50%;z-index:-2;">
<b >Button 1 </b>
<small>{{btn_status}}</small>
</button>
<button class="tablinks" [class.active]="activeTab=='btn2'" (click)="clickType('btn2')" style="width: 50%;margin-left: -90px;">
<b>Button 2</b>
<small>{{btn_status}}</small>
</button>
</div>

我认为有比将一个按钮叠加在另一个按钮之上更好的方法。有人可以提供更好的解决方案吗?

最佳答案

我更改了 css 和 Angular 代码,因此该示例有效。添加了 z-indexposition: relative 以使其工作。应该很容易装回去。

.tab {
overflow: hidden;
}

.tab button {
position: relative;
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
border-radius: 30px;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
border:1px solid #cccc;
color: #676767;
z-index: 1;
width: 50%;
}
.tab button.active {
z-index: 2;
color:#ffffff ;
background-color: #009bdf;
}
 <div class="tab" style="width: 100%;">
<button class="tablinks active">
<b>Button 1</b>
<small>selected</small>
</button>
<button class="tablinks" style="margin-left: -90px;">
<b>Button 2</b>
<small></small>
</button>
</div>
<br/>
<div class="tab" style="width: 100%;">
<button class="tablinks">
<b>Button 1</b>
<small></small>
</button>
<button class="tablinks active" style="margin-left: -90px;">
<b>Button 2</b>
<small>selected</small>
</button>
</div>

关于javascript - 如何使两个按钮像切换按钮一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52867738/

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