I am new to jQuery, so I apologize for trivial questions.
I'm trying to write a simple tabbed web page. Everything works except the selected tab does not change to the selected tab color/text. I have a css that I use to control active/selected tabs. It works for hovering (the tab changes to hover color). But after the tab is clicked it goes back to the unselected color.
I am not using the default jqueryui.css because I'm trying to build and learn things on my own. But here I'm stumped. I've tried adding all sorts of variations of .ui-tabs-selected and .ui-state-active to my css, to no avail.
Using the code inspector in chrome, I see that jquery applies the styles ui-state-active and ui-tabs-selected. But how do I specify them in css to be activated?
Thank you!
here are the code snippets:
html:
<html>
<head>
<title>Patient Records Dashboard</title>
<link rel="stylesheet" type="text/css" href="css/tabs2.css" media="screen">
<link rel="stylesheet" type="text/css" href="css/tables.css" media="screen">
</head>
<body>
<div id="tabbed_box_1" class="tabbed_box">
<div class="tabbed_area">
<h4>My title</h4>
<div id="tabs">
<ul class="tabs">
<li><a href="#tab1" >A</a></li>
<li><a href="#tab2" >B</a></li>
<li><a href="#tab3" >C</a></li>
<li><a href="#tab4" >D</a></li>
</ul>
<div id="tab1_content" class="content">
<p>This is the text for tab 1</p>
</div>
<div id="tab2_content" class="content">
<p>This is the text for tab 2</p>
</div>
<div id="tab3_content" class="content">
<p>This is the text for tab 3</p>
</div>
<div id="tab4_content" class="content">
<p>This is the text for tab 4</p>
</div>
</div>
</div> <!- End of tabbed_area->
</div> <!– End of tabbed_box_1 –>
<script type="text/javascript" src="js/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript" ></script>
<script type="text/javascript">
$(document).ready(function() {
$("#tabs").tabs();
});
</script>
</body>
</html>
css:
body {
background-color:#687f93;
margin:40px;
}
#tabbed_box {
margin: 0px auto 0px auto;
width:300px;
}
.tabbed_box h4 {
font-family:Arial, Helvetica, sans-serif;
font-size:23px;
color:#ffffff;
letter-spacing:-1px;
margin-bottom:10px;
}
.tabbed_box h4 small {
color:#e3e9ec;
font-weight:normal;
font-size:9px;
font-family:Verdana, Arial, Helvetica, sans-serif;
text-transform:uppercase;
position:relative;
top:-4px;
left:6px;
letter-spacing:0px;
}
.tabbed_area {
border:1px solid #494e52;
background-color:#748593;
padding:8px;
}
ul.tabs {
margin:0px; padding:0px;
}
ul.tabs li {
list-style:none;
display:inline;
}
ul.tabs li a {
background-color:#464c54;
color:#ffebb5;
padding:8px 14px 8px 14px;
text-decoration:none;
font-size:9px;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-weight:bold;
text-transform:uppercase;
border:1px solid #464c54;
background-image:url(../images/tab_off.jpg);
background-repeat:repeat-x;
background-position:bottom;
}
ul.tabs li a:hover {
background-position: -420px -31px;
color:#fff;
background-color:#2f343a;
border-color:#2f343a;
}
ul.tabs li a.current, ul.tabs li a.current:hover, ul.tabs li.current a, .ui-tabs-nav li.ui-state-active, .ui-state-active, .ui-tabs-selected {
background-color:#ffffff;
color:#282e32;
border:1px solid #464c54;
border-bottom: 1px solid #ffffff;
background-image:url(../images/tab_on.jpg);
background-repeat:repeat-x;
background-position: -420px -62px;
}
.content {
background-color:#ffffff;
padding:10px;
border:1px solid #464c54;
background-image:url(../images/content_bottom.jpg);
background-repeat:repeat-x;
background-position:bottom;
}
ul.tabs {
margin:0px; padding:0px;
margin-top:5px;
margin-bottom:6px;
}
.content ul {
margin:0px;
padding:0px 20px 0px 20px;
}
.content ul li {
list-style:none;
border-bottom:1px solid #d6dde0;
padding-top:15px;
padding-bottom:15px;
font-size:13px;
}
.content ul li a {
text-decoration:none;
color:#3e4346;
}
.content ul li a small {
color:#8b959c;
font-size:9px;
text-transform:uppercase;
font-family:Verdana, Arial, Helvetica, sans-serif;
position:relative;
left:4px;
top:0px;
}
.content ul li:last-child {
border-bottom:none;
}
.ui-tabs-hide { display:none; }
Add to CSS
ul.tabs li.ui-state-active,ul.tabs li.ui-tabs-selected { your styling }
ul.tabs li.ui-tabs-active a, ul.tabs li.ui-tabs-selected a{ your styling }
In HTML change
id="tab1_content" to id="tab1"
id="tab2_content" to id="tab2"
id="tab3_content" to id="tab3"
id="tab4_content" to id="tab4"
In your CSS code all styling is applied to the a
>> ul.tabs li a
but ui-state-active
and ui-tabs-selected
styling you apply to the li
, not a
. It is the reason why you can't see it.