2016-08-03 132 views
0

我試圖更改我的選項卡菜單中活動標題選項卡的背景顏色。如何使用css更改選項卡標題背景的活動顏色

標籤

li.is-active { 
 
    
 
    background-color:blue; 
 
    
 
    }
 <div class="row"> 
 
     <div class="medium-12 columns"> 
 
    <ul class="tabs" data-tabs id="authentication_tab"> 
 
     <li class="tabs-title is-active"><a href="#panel1" aria-selected="true">Tab 1</a></li> 
 
     <li class="tabs-title"><a href="#panel2">Tab 2</a></li> 
 
    </ul> 
 
    <div class="tabs-content" data-tabs-content="authentication_tab"> 
 
     <div class="tabs-panel is-active" id="panel1"> 
 
     <p>Vivamus hendrerit arcu sed erat molestie vehicula. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor. Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus.</p> 
 
     </div> 
 
     <div class="tabs-panel" id="panel2"> 
 
     <p>Suspendisse dictum feugiat nisl ut dapibus. Vivamus hendrerit arcu sed erat molestie vehicula. Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor.</p> 
 
     </div> 
 
    </div> 
 
    </div> 
 
    </div>

+0

似乎在這撥弄工作正常:

要引用的jQuery,您的文檔的<head>中添加此https://jsfiddle.net/dvo37ca1/你能用jsfiddle重現這個問題嗎? –

+1

你將需要一些JS刪除並添加is-active類的點擊 –

回答

0

使用jQuery(很多的情況下,意見的jQuery的語法是新的給你):

// Bind a function to the `click` event of elements matching the selector `.tabs-title` 
// Note that within a jQuery function, `$(this)` is the current element represented as a jQuery element object. 
$(".tabs-title > a").click(function() { 
    // For each element with the class selector `.tabs-title` 
    $(".tabs-title").each(function() { 
     // Remove the class "is-active" from the current element in the loop 
     $(this).removeClass("is-active") 
    }) 

    // Get the parent of the clicked `a` element (i.e., the `.tabs-title` element), then add the class. 
    $(this).parent().addClass("is-active"); 
}) 

jsFiddle

編輯

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> 
+0

它不工作時,我實現它 – thomaSmith

+0

它絕對工作 - 檢查jsFiddle。你是否準確地複製了代碼?你是否也在HTML代碼中引用了jQuery?我會更新如何做到這一點的答案。 –

+0

@thomaSmith查看更新。 –