Nav tabs with if statments - tabs

I have bootstrap nav taps working with if statements to dynamically fill content. What I am trying to accomplish is have the tabs fade state switched to active (expanded) if the if condition is meet. Right now "Green" shows active and I can click the other tabs just fine to expose the content. So if Green has no content, show Red, if Red has no content show Yellow. This would all be on first page visit with the content expanded.
There will always be content in Yellow, Orange and Blue.
I am struggling with how to best approach this? Any hints would be appreciated.
Sorry don't know how to include if statements with jfiddle. jfiddle
<ul id="tabs" class="nav nav-tabs nav-fill">
{ if green }
<li class="active nav-item"><a data-toggle="tab" href="#1">Green</a></li>
{ endif }
{ if red }
<li class="nav-item"><a data-toggle="tab" href="#2">Red</a></li>
{ endif }
<li class="nav-item"><a data-toggle="tab" href="#3">Yellow</a></li>
<li class="nav-item"><a data-toggle="tab" href="#4">Orange</a></li>
<li class="nav-item"><a data-toggle="tab" href="#5">Blue</a></li>
</ul>
<div class="tab-content">
<div id="color-featured" class="tab-pane active">
<div class="color-tab-item">
{ if green }
<div>{green}</div>
{ endif }
</div>
</div>
<div id="2" class="tab-pane fade">
{ if red }
<div class="red"> {red}</div>
{ endif }
</div>
<div id="3" class="tab-pane fade">
<div class="yellow"> {yellow}</div>
</div>
<div id="4" class="tab-pane fade">
{orange}
</div>
<div id="5" class="tab-pane fade">
{blue}
</div>
</div>

Related

Nested tabs in a pill tab panel not working in Bootstrap

I'm having trouble getting tabs inside of a vertical pill tab panel to work correctly in Bootstrap 4.
Here's a minimal code example:
<html>
<head>
<link href="bootstrap.min.css" rel="stylesheet">
</head>
<body>
<script src="popper.min.js"></script>
<script src="jquery-3.2.1.min.js"></script>
<script src="bootstrap.min.js"></script>
<div class="row">
<div class="col-2">
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist">
<a class="nav-link active" data-toggle="pill" href="#v-pills-1" role="tab">Pill 1</a>
<a class="nav-link" data-toggle="pill" href="#v-pills-2" role="tab">Pill 2</a>
<a class="nav-link" data-toggle="pill" href="#v-pills-3" role="tab">Pill 3</a>
</div>
</div>
<div class="col-10">
<div class="tab-content" id="v-pills-tabContent">
<div class="tab-pane fade active show" id="v-pills-1" role="tabpanel">
Pill 1 content
<!-- tabs
<ul class="nav nav-tabs nav-fill" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#tabs-1" role="tab">Tab 1</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tabs-2" role="tab">Tab 2</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tabs-3" role="tab">Tab 3</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active show" id="tabs-1" role="tabpanel">Tab 1 content</div>
<div class="tab-pane" id="tabs-2" role="tabpanel">Tab 2 content</div>
<div class="tab-pane" id="tabs-3" role="tabpanel">Tab 3 content</div>
</div>
-->
</div>
<div class="tab-pane fade" id="v-pills-2" role="tabpanel">Pill 2 content</div>
<div class="tab-pane fade" id="v-pills-3" role="tabpanel">Pill 3 content</div>
</div>
</div>
</div>
</body>
</html>
The webpage functions correctly, that is the vertical pills work as expected. Once you uncomment the section that gives the first vertical pill a nested tab, the pills do not function correctly. Clicking on Pill 2 and then Pill 3 will results in the content for both pills to be shown.
Why doesn't this work and how can I fix it?
This is a bug in version 4.0.0-beta. It is fixed in version 4.0.0-beta.2:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>

HTML navigation tabs doesn't work

Hi I have complication regarding on bootstrap. My code doesn't work is there something wrong? any idea to solve the problem?--thanks
<nav id='nav-reservation'>
<div class="container">
<ul class="nav nav-tabs">
<a href='resource-index.php?page=room' class='nav-reservation-item <?php if($_REQUEST[' page '] == "room"){ echo "active"; } ?>'>Room</a>
<a href='resource-index.php?page=equipment' class='nav-reservation-item <?php if($_REQUEST[' page '] == "equipment"){ echo "active"; } ?>'>Equipment </a>
</ul>
</div>
<div class="tab-content">
<div id="room" class="tab-pane fade in active"></div>
<div id="equipment" class="tab-pane fade in active"></div>
</div>
</nav>
You forgot to add li tag in ul tag.
<nav id='nav-reservation'>
<div class="container">
<ul class="nav nav-tabs">
<li> <a href='resource-index.php?page=room' class='nav-reservation-item <?php if($_REQUEST[' page '] == "room"){ echo "active"; } ?>'>Room</a></li>
<li> <a href='resource-index.php?page=equipment' class='nav-reservation-item <?php if($_REQUEST[' page '] == "equipment"){ echo "active"; } ?>'>Equipment </a></li>
</ul>
</div>
<div class="tab-content">
<div id="room" class="tab-pane fade in active"></div>
<div id="equipment" class="tab-pane fade in active"></div>
</div>
The first thing is that you have both of your tab content pane's with the in active classes on them and the only one that should have these classes is the active open pane. Having both of these with the in active classes will show both of the tabs at the same time.
Next the tabs are activated by a hashtag in the href of the nav tabs. And you have no hashtag. They should correspond with the tab pane that you want to open. So if you want to open the tab with the id #room in the href in the nav tabs you should specify this. Also you should put the data-toggle="tab" in the href as well like so:
<a data-toggle="tab" href="#room">Room</a>
This will open the tab with the id #room
So your markup should look something like the following without your custom php:
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#room">Room</a></li>
<li><a data-toggle="tab" href="#equipment">Equipment</a></li>
</ul>
<div class="tab-content">
<div id="room" class="tab-pane fade in active">
First Tab
</div>
<div id="equipment" class="tab-pane fade">
Second Tab
</div>
</div>

How to set tabs according specific grids in bootstrap?

I'll be glad if you can help me on a specific issue for which I haven't find
any solution for that.
I have to make a web page in bootstrap which includes horizontal tabs.
The issue is that I need that The first tab will start from the
2nd grid and beyond as seen below:
I tried with my code but nothing works as expected in the image above:
.nav-tabs-colors {
background-color: #ececef;
}
.edit-app-tabs {
background-color:#ececef;
}
#edit-app-tab {
background-color:#ececef;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="tabbable edit-app-tabs">
<ul class="nav nav-tabs nav-tabs-colors">
<div class="col-lg-offset-1"><li role="presentation"></li></div>
<li role="presentation">Tab1</li>
<li role="presentation" class="active">Tab2</li>
<li role="presentation">Tab3</li>
<li role="presentation">Tab4</li>
<li role="presentation">Tab5</li>
<li role="presentation">Tab6</li>
<li role="presentation">Tab7</li>
<li role="presentation">Tab8</li>
</ul>
<div class="tab-content">
<div id="edit-app-tab" class="tab-pane fade in active">
<div class="row">
<h3>Content Content Content</h3>
</div>
</div>
</div>
<div>
Can you please show me how to exact fit the tabs according to specific grid ?
Thanks in Advance for your help!
EVH671
You could for instance put your tabs into a divider with col-md-offset-1 class
.nav-tabs-colors {
background-color: #ececef;
}
.edit-app-tabs {
background-color: #ececef;
}
#edit-app-tab {
background-color: #ececef;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="tabbable edit-app-tabs">
<ul class="nav nav-tabs nav-tabs-colors col-md-offset-1">
<div class="">
<li role="presentation"></li>
</div>
<li role="presentation">Tab1
</li>
<li role="presentation" class="active">Tab2
</li>
<li role="presentation">Tab3
</li>
<li role="presentation">Tab4
</li>
<li role="presentation">Tab5
</li>
<li role="presentation">Tab6
</li>
<li role="presentation">Tab7
</li>
<li role="presentation">Tab8
</li>
</ul>
<div class="tab-content">
<div id="edit-app-tab" class="tab-pane fade in active">
<div class="row">
<h3>Content Content Content</h3>
</div>
</div>
</div>
<div>
More on grids: http://getbootstrap.com/css/#grid
Bare in mind that this offset's the div by 1 column in medum viewport and up.
and it'd be wise to have your whole layout structured properly with containers, rows and columns.

bootstrap3 nav-tabs not switching tabs

This is currently the code I'm working with.
I want it to be able to switch tabs however it does not. I've tried taking off the active class however it still doesn't work.
I followed a tutorial to do it this way which didn't require JavaScript.
Can anyone help me find out why it is not working?
<div class="nav">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#Home">Home</a></li>
<li><a data-toggle="tab" href="#Tournaments">Tournaments</a></li>
<li><a data-toggle="tab" href="#About">About</a></li>
<li><a data-toggle="tab" href="#Contact">Contact</a></li>
</ul>
</div>
<div class="tab-content">
<div id="Home" class="tab-pane fade">
<h3> example </h3>
</div>
<div id="Tournaments" class="tab-pane fade">
<h3>create images to show for new pages</h3>
</div>
<div id="About" class="tab-pane fade">
<h3>6214</h3>
</div>
<div id="Contact" class="tab-pane fade">
<h3>exds</h3>
</div>
</div>
You are missing all javascripts.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
Refer to this : https://codepen.io/jrcanicula/pen/vmojRG

glyph-icon size within a tab

http://jsfiddle.net/r9dunwzs/1/
<ul id="myTab" class="nav nav-tabs">
<li class="active">one</li>
<li>
<a href="#profile" data-toggle="tab">
<i class="glyphicon glyphicon-exclamation-sign" style="font-size: 25px"></i>
</a>
</li>
</ul>
As you can see in jsFiddle, I'm having problems to increase the font size of an icon within a tab in bootstrap 3.
The expected behaviour is the following:
but when I increase the font-size my tabs get deformed:
How can I increase the glyph-icon size without deforming my tabs ?
Add a class to the a href of the icon and set a new line-height to the icon
HTML
<div class="bs-docs-example">
<ul id="myTab" class="nav nav-tabs">
<li class="active">one</li>
<li>
<a href="#profile" data-toggle="tab" class="bicon">
<i class="glyphicon glyphicon-exclamation-sign" style="font-size: 25px"></i>
</a>
</li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="home">
1
</div>
<div class="tab-pane fade" id="profile">
2
</div>
</div>
</div>
CSS
a.bicon{ padding: 0px 6px !important;
}
a.bicon i{ line-height: 1.45em !important;
}
DEMO HERE