2015-10-17 60 views
0

我有一個水平HTML選項卡,其中我希望隱藏所選選項卡的底部邊框。隱藏HTML中選定選項卡的底部邊框

下面是當前的代碼,我有 - https://jsfiddle.net/vgx2k7p5/

這個問題已經被問herehere

但這兩種解決方案都不能正常工作,因爲我使用一個div結構,沒有太大的JavaScript。

jQuery('.tab-links a').on('click', function(e) { 
 

 
    var currentAttrValue = jQuery(this).attr('href'); 
 

 
    jQuery(currentAttrValue).show().siblings().hide(); //changed here 
 
    jQuery(this).parent('li').addClass('active').siblings().removeClass('active'); 
 
    e.preventDefault(); 
 
});
.tabs { 
 
    width: 90%; 
 
    margin: auto; 
 
} 
 
/*----- Tab Links -----*/ 
 

 
/* Clearfix */ 
 

 
.tab-links:after { 
 
    display: block; 
 
    clear: both; 
 
    content: ''; 
 
} 
 
.tab-links { 
 
    margin: 0px; 
 
} 
 
.tab-links li { 
 
    margin: 0px 3px; 
 
    float: left; 
 
    list-style: none; 
 
} 
 
.tab-links a { 
 
    padding: 9px 15px; 
 
    display: inline-block; 
 
    border-radius: 3px 3px 0px 0px; 
 
    text-decoration: none; 
 
    font-size: 16px; 
 
    font-weight: 600; 
 
    color: #999; 
 
    transition: all linear 0.2s; 
 
    border: 1px solid #fff; 
 
} 
 
.tab-links a:hover { 
 
    text-decoration: none; 
 
    /*background: #f1f1f1;*/ 
 
    /*border-bottom: 4px solid #999; */ 
 
} 
 
li.active a, 
 
li.active a:hover { 
 
    /* border-bottom: 4px solid #444; */ 
 
    /*background: #ccc;*/ 
 
    border: 1px solid #ccc; 
 
    border-bottom: 1px solid #fff; 
 
    color: #444; 
 
} 
 
/*----- Content of Tabs -----*/ 
 

 
.tab-content { 
 
    padding: 15px; 
 
    border-radius: 3px; 
 
    border: 1px solid #ccc; 
 
    background: #fff; 
 
    min-height: 300px; 
 
    z-index: -99; 
 
} 
 
.tab { 
 
    display: none; 
 
    min-height: 300px; 
 
} 
 
.tab.active { 
 
    display: block; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<div class="tabs margintop20"> 
 
    <ul class="tab-links"> 
 
    <li class="active"><a href="#tab1">PROFILE</a> 
 
    </li> 
 
    <li><a href="#tab2">REVIEWS</a> 
 
    </li> 
 
    <li><a href="#tab3">REWARDS</a> 
 
    </li> 
 

 
    </ul> 
 

 
    <div class="tab-content"> 
 
    <div id="tab1" class="tab active clearfix"> 
 

 

 
    </div> 
 

 
    <div id="tab2" class="tab"> 
 

 
    </div> 
 

 
    <div id="tab3" class="tab"> 
 
     <h3>Videos and Screenshots</h3> 
 

 
    </div> 
 

 

 
    </div> 
 
</div> 
 

 
</div>

我到底做錯了什麼?設置Z-index和增加border-bottom寬度都不起作用。

回答

1

我已經與更新你的CSS:

/* ADDED */ 
.tab-links .active{ 
    margin-top : 1px; 
} 
.active > a { 
    margin-bottom: -1px; 
} 

而現在它似乎是工作!


jQuery('.tab-links a').on('click', function(e) { 
 

 
    var currentAttrValue = jQuery(this).attr('href'); 
 

 
    jQuery(currentAttrValue).show().siblings().hide(); //changed here 
 
    jQuery(this).parent('li').addClass('active').siblings().removeClass('active'); 
 
    e.preventDefault(); 
 
});
.tabs { 
 
    width: 90%; 
 
    margin: auto; 
 
} 
 
/*----- Tab Links -----*/ 
 

 
/* Clearfix */ 
 

 
.tab-links:after { 
 
    display: block; 
 
    clear: both; 
 
    content: ''; 
 
} 
 
.tab-links { 
 
    margin: 0px; 
 
} 
 
.tab-links li { 
 
    margin: 0px 3px; 
 
    float: left; 
 
    list-style: none; 
 
} 
 
.tab-links a { 
 
    padding: 9px 15px; 
 
    display: inline-block; 
 
    border-radius: 3px 3px 0px 0px; 
 
    text-decoration: none; 
 
    font-size: 16px; 
 
    font-weight: 600; 
 
    color: #999; 
 
    transition: all linear 0.2s; 
 
    border: 1px solid #fff; 
 
} 
 
.tab-links a:hover { 
 
    text-decoration: none; 
 
    /*background: #f1f1f1;*/ 
 
    /*border-bottom: 4px solid #999; */ 
 
} 
 
li.active a, 
 
li.active a:hover { 
 
    /* border-bottom: 4px solid #444; */ 
 
    /*background: #ccc;*/ 
 
    border: 1px solid #ccc; 
 
    border-bottom: 1px solid #fff; 
 
    color: #444; 
 
} 
 

 

 

 
/*----- Content of Tabs -----*/ 
 

 
.tab-content { 
 
    padding: 15px; 
 
    border-radius: 3px; 
 
    border: 1px solid #ccc; 
 
    background: #fff; 
 
    min-height: 300px; 
 
    z-index: -99; 
 
} 
 
.tab { 
 
    display: none; 
 
    min-height: 300px; 
 
} 
 
.tab.active { 
 
    display: block; 
 
} 
 

 

 
/* ADDED */ 
 
.tab-links .active{ 
 
    margin-top : 1px; 
 
    } 
 
.active > a { 
 
    margin-bottom: -1px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<div class="tabs margintop20"> 
 
    <ul class="tab-links"> 
 
    <li class="active"><a href="#tab1">PROFILE</a> 
 
    </li> 
 
    <li><a href="#tab2">REVIEWS</a> 
 
    </li> 
 
    <li><a href="#tab3">REWARDS</a> 
 
    </li> 
 

 
    </ul> 
 

 
    <div class="tab-content"> 
 
    <div id="tab1" class="tab active clearfix"> 
 

 

 
    </div> 
 

 
    <div id="tab2" class="tab"> 
 

 
    </div> 
 

 
    <div id="tab3" class="tab"> 
 
     <h3>Videos and Screenshots</h3> 
 

 
    </div> 
 

 

 
    </div> 
 
</div> 
 

 
</div>