/    Sign up×
Community /Pin to ProfileBookmark

JavaScript/CSS Custom Tabs

I have some custom navigation tabs that when clicked, reveal relevant content. They are created by HTML, CSS & JavaScript.
The only thing that I need to accomplish with these tabs now, is to have
the first tab: <li class=”tab-link current” data-tab=”tab-1″><a> News</a></li> to be the only one showing
when the page loads.

Here are the three pieces of code:

HTML

[code]<ul class=”tabs nav nav-pills nav-justified”>
<li class=”tab-link current” data-tab=”tab-1″><a> News</a></li>
<li class=”tab-link” data-tab=”tab-2″><a>Industry News</a></li>
<li class=”tab-link” data-tab=”tab-3″><a>Events</a></li>
<li class=”tab-link” data-tab=”tab-4″><a>New Documents</a></li>
</ul>[/code]

Css

[code]/*
1.Add following css to Page Settings:
.tab-content{
display: none;
background: #ededed;
padding: 15px;
}
.tab-content.current{
display: inherit;
}
2. Add custom css classes “tab-content tab-1 current” to first row.
Add custom css classes “tab-content tab-2” to following row etc.
*/
#@{uniqueId} {
font-family: Lato, ‘Segoe UI’, ‘Helvetica Neue’, sans-serif;
font-weight: lighter;
text-align: center;
color: @color;
}
ul.tabs{
margin: 0px;
padding: 0px;
list-style: none;
}
ul.tabs li{
cursor: pointer;
vertical-align: middle;
&:hover{background: #ededed;}
a{
color: rgb(238, 36, 137);
font-family: ‘Raleway’, sans-serif;
font-size: 20px;
font-weight: bold;
}
a:hover{background-color: transparent;}
}
ul.tabs li.current{
//background: #ededed;
color: #222;
border-bottom: 4px solid rgb(62, 194, 154);
a{
color:rgb(0,190,33);
}
}[/code]

JavaScript

[code]$(‘ul.tabs li’).click(function(){
var tab_id = $(this).attr(‘data-tab’);
$(‘ul.tabs li’).removeClass(‘current’);
$(‘.tab-content’).removeClass(‘current’);
$(this).addClass(‘current’);
$(“.”+tab_id).addClass(‘current’);
})[/code]

I’m trying to get the first “News” tab to open only on page load.
Any help would be greatly appreciated.![](src)

**Edited by site staff: Inserted code tags**

to post a comment
CSSHTMLJavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumMar 17.2020 — Obviously you are using some precompiler for your CSS. Please post the compiled CSS too.

BTW: Please use code tags when posting code: `your code here`

I've editet your posting accordingly.
Copy linkTweet thisAlerts:
@guildwebservicesauthorMar 17.2020 — I'm using LiveTiles Designer as the compiler; which sits over SharePoint Online.
×

Success!

Help @guildwebservices spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...