gpt4 book ai didi

jquery - 选项卡样式不适用

转载 作者:行者123 更新时间:2023-11-28 08:10:37 24 4
gpt4 key购买 nike

如何在单击链接时动态地将负 margin-bottom 应用于元素。尝试在单击选项卡时删除选项卡的底部边框。当我对 tab 元素应用负边距时,它起作用了,但它应用于所有看起来很有趣的选项卡。有人可以看一下吗?

jQuery(document).ready(function() {
jQuery('.tabs .tab-links a').on('click', function(e) {
var currentAttrValue = jQuery(this).attr('href');

// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).show().siblings().hide();

// Change/remove current tab to active
jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
// tried adding this code but it doesn't seem to work
$(function() {
$('tab-links a').click(function () {
$( ".tab-links.active" ).css('margin-bottom','-2px');
});
});


e.preventDefault();

});
});
/*----- Tabs -----*/
.tabs {
width:100%;
display:inline-block;
}

/*----- Tab Links -----*/
/* Clearfix */
.tab-links:after {
display:block;
clear:both;
content:'';
margin-bottom: -18px;
}

.tab-links li {
margin:0px 5px;
margin-bottom: 0px;
float:left;
list-style:none;
border-radius:3px 3px 0px 0px;
border: 2px solid black;
margin-bottom: -2px;



}
.tab-links li.active {
border-bottom: none;
/*margin-bottom: -2px; tried declaring a margin here but it didn't work */

}

.tab-links a {
padding:10px 15px;
display:inline-block;
border-radius:3px 3px 0px 0px;
background:#7FB5DA;
font-size:16px;
font-weight:600;
color:#4c4c4c;
transition:all linear 0.15s;


}

.tab-links a:hover {
background:#a7cce5;
text-decoration:none;
}

li.active a {
background:#fff;
color:#4c4c4c;
border-bottom: none;
}
li.active a {
border-bottom: none;
}
/*----- Content of Tabs -----*/
.tab-content {
padding: 0 10px 10px 10px;
border-radius:3px;
box-shadow:-1px 1px 1px rgba(0,0,0,0.15);
background:#fff;
border: 2px solid black;


}

.tab {
display:none;
}

.tab.active {
display:block;
}
<body>
<div class="tabs">
<ul class="tab-links">
<li class="active"><a href="#tab1">Tab #1</a></li>
<li><a href="#tab2">Tab #2</a></li>
<li><a href="#tab3">Tab #3</a></li>
<li><a href="#tab4">Tab #4</a></li>
</ul>
<div class="tab-content">
<div id="tab1" class="tab active">
<p>Tab #1 content goes here!</p>
<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis.</p>
</div>

<div id="tab2" class="tab">
<p>Tab #2 content goes here!</p>
<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis. In hac habitasse platea dictumst. Ut euismod tempus hendrerit. Morbi ut adipiscing nisi. Etiam rutrum sodales gravida! Aliquam tellus orci, iaculis vel.</p>
</div>

<div id="tab3" class="tab">
<p>Tab #3 content goes here!</p>
<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum ri.</p>
</div>

<div id="tab4" class="tab">
<p>Tab #4 content goes here!</p>
<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis. In hac habitasse platea dictumst. Ut euismod tempus hendrerit. Morbi ut adipiscing nisi. Etiam rutrum sodales gravida! Aliquam tellus orci, iaculis vel.</p>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script>
</body>

最佳答案

尝试像这样使用 toggleClass:

JS:

$( ".tab-links a" ).click(function() {
$( this ).toggleClass( "neq-margin" );
});

CSS:

.neq-margin  {
margin-bottom: -2px;
}

关于jquery - 选项卡样式不适用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29290304/

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