Reputation: 497
I have a active class that I applied border
.tabs-nav .tab-active a {
border-bottom: 3px solid red;
cursor: default;
}
But the problem is the border looks like it's outside the box when I hover, how to make it inside? means I want a straight line for the tab items with active border.
demo https://jsfiddle.net/eztskazd/
Upvotes: 0
Views: 1265
Reputation: 357
This is what You want? Just replace your entire css with below and check:
ul,
li,
div {
background: hsla(0, 0%, 0%, 0);
border: 0;
font-size: 100%;
margin: 0;
outline: 0;
padding: 0;
vertical-align: baseline;
font: 13px/20px "Droid Sans", Arial, "Helvetica Neue", "Lucida Grande", sans-serif;
text-shadow: 0 1px 0 hsl(0, 100%, 100%);
}
li {
display: list-item;
text-align: -webkit-match-parent;
}
.tabs-nav {
list-style: none;
margin: 0;
padding: 0;
}
.tabs-nav li:first-child a {
border-right: 0;
}
a:hover {
background: #eee;
border-bottom: 3px solid red;
cursor: default;
}
.tabs-nav a {
background: hsl(120, 11%, 96%);
color: hsl(215, 6%, 57%);
display: block;
font-size: 11px;
font-weight: bold;
height: 40px;
line-height: 44px;
text-align: center;
text-transform: uppercase;
width: 140px;
}
.tabs-nav li {
float: left;
}
.tabs-stage {
border: 1px solid hsl(210, 6%, 79%);
-webkit-border-radius: 0 0 6px 6px;
-moz-border-radius: 0 0 6px 6px;
-ms-border-radius: 0 0 6px 6px;
-o-border-radius: 0 0 6px 6px;
border-radius: 0 0 6px 6px;
border-top: 0;
clear: both;
margin-bottom: 20px;
position: relative;
top: -1px;
width: 281px;
}
.tabs-stage p {
margin: 0;
padding: 20px;
color: hsl(0, 0%, 33%);
}
Upvotes: 0
Reputation: 1655
From W3schools on the border-box
value of box-sizing
:
The width and height properties (and min/max properties) includes content, padding and border
.tabs-nav .tab-active a {
border-bottom: 3px solid red;
box-sizing: border-box;
cursor: default;
}
https://jsfiddle.net/eztskazd/10/
Upvotes: 0
Reputation: 16855
You will need to set the box-sizing:border-box
to the element to tell that any padding and border values to the element will be included to the element width and height.
// From http://learn.shayhowe.com/advanced-html-css/jquery
// Change tab class and display content
$('.tabs-nav a').on('click', function(event) {
event.preventDefault();
$('.tab-active').removeClass('tab-active');
$(this).parent().addClass('tab-active');
$('.tabs-stage div').hide();
$($(this).attr('href')).show();
});
$('.tabs-nav a:first').trigger('click'); // Default
* {
box-sizing: border-box;
}
ul,
li,
div {
background: hsla(0, 0%, 0%, 0);
border: 0;
font-size: 100%;
margin: 0;
outline: 0;
padding: 0;
vertical-align: baseline;
font: 13px/20px "Droid Sans", Arial, "Helvetica Neue", "Lucida Grande", sans-serif;
text-shadow: 0 1px 0 hsl(0, 100%, 100%);
}
li {
display: list-item;
text-align: -webkit-match-parent;
}
.tabs-nav li :hover {
background: #eee;
}
.tabs-nav {
list-style: none;
margin: 0;
padding: 0;
}
.tabs-nav li:first-child a {
border-right: 0;
}
.tabs-nav .tab-active a {
border-bottom: 3px solid red;
cursor: default;
}
.tabs-nav a {
background: hsl(120, 11%, 96%);
color: hsl(215, 6%, 57%);
display: block;
font-size: 11px;
font-weight: bold;
height: 40px;
line-height: 44px;
text-align: center;
text-transform: uppercase;
width: 140px;
}
.tabs-nav li {
float: left;
}
.tabs-stage {
border: 1px solid hsl(210, 6%, 79%);
-webkit-border-radius: 0 0 6px 6px;
-moz-border-radius: 0 0 6px 6px;
-ms-border-radius: 0 0 6px 6px;
-o-border-radius: 0 0 6px 6px;
border-radius: 0 0 6px 6px;
border-top: 0;
clear: both;
margin-bottom: 20px;
position: relative;
top: -1px;
width: 281px;
}
.tabs-stage p {
margin: 0;
padding: 20px;
color: hsl(0, 0%, 33%);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="tabs-nav">
<li class=""><a href="#tab-1" rel="nofollow">Features</a>
</li>
<li class="tab-active"><a href="#tab-2" rel="nofollow">Details</a>
</li>
</ul>
<div class="tabs-stage">
<div id="tab-1" style="display: none;">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus nec neque nisi, dictum aliquet lectus.</p>
</div>
<div id="tab-2" style="display: block;">
<p>Phasellus pharetra aliquet viverra. Donec scelerisque tincidunt diam, eu fringilla urna auctor at.</p>
</div>
</div>
Or you can apply the border by default to the a
same as background color and change that color on .active
state
// From http://learn.shayhowe.com/advanced-html-css/jquery
// Change tab class and display content
$('.tabs-nav a').on('click', function(event) {
event.preventDefault();
$('.tab-active').removeClass('tab-active');
$(this).parent().addClass('tab-active');
$('.tabs-stage div').hide();
$($(this).attr('href')).show();
});
$('.tabs-nav a:first').trigger('click'); // Default
ul,
li,
div {
background: hsla(0, 0%, 0%, 0);
border: 0;
font-size: 100%;
margin: 0;
outline: 0;
padding: 0;
vertical-align: baseline;
font: 13px/20px "Droid Sans", Arial, "Helvetica Neue", "Lucida Grande", sans-serif;
text-shadow: 0 1px 0 hsl(0, 100%, 100%);
}
li {
display: list-item;
text-align: -webkit-match-parent;
}
.tabs-nav li :hover {
background: #eee;
}
.tabs-nav {
list-style: none;
margin: 0;
padding: 0;
}
.tabs-nav li:first-child a {
border-right: 0;
}
.tabs-nav .tab-active a {
border-bottom-color: red;
cursor: default;
}
.tabs-nav a {
border-bottom: 3px solid hsl(120, 11%, 96%);
background: hsl(120, 11%, 96%);
color: hsl(215, 6%, 57%);
display: block;
font-size: 11px;
font-weight: bold;
height: 40px;
line-height: 44px;
text-align: center;
text-transform: uppercase;
width: 140px;
}
.tabs-nav li {
float: left;
}
.tabs-stage {
border: 1px solid hsl(210, 6%, 79%);
-webkit-border-radius: 0 0 6px 6px;
-moz-border-radius: 0 0 6px 6px;
-ms-border-radius: 0 0 6px 6px;
-o-border-radius: 0 0 6px 6px;
border-radius: 0 0 6px 6px;
border-top: 0;
clear: both;
margin-bottom: 20px;
position: relative;
top: -1px;
width: 281px;
}
.tabs-stage p {
margin: 0;
padding: 20px;
color: hsl(0, 0%, 33%);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="tabs-nav">
<li class=""><a href="#tab-1" rel="nofollow">Features</a>
</li>
<li class="tab-active"><a href="#tab-2" rel="nofollow">Details</a>
</li>
</ul>
<div class="tabs-stage">
<div id="tab-1" style="display: none;">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus nec neque nisi, dictum aliquet lectus.</p>
</div>
<div id="tab-2" style="display: block;">
<p>Phasellus pharetra aliquet viverra. Donec scelerisque tincidunt diam, eu fringilla urna auctor at.</p>
</div>
</div>
Upvotes: 1
Reputation: 6742
You can achieve this if you use box-sizing: border-box;
.
To fix your specific problem, you can use the following:
.tabs-nav .tab-active a {
border-bottom: 3px solid red;
cursor: default;
box-sizing: border-box;
}
Maybe you can also apply box-sizing: border-box globally, you have to try this for yourself. See also this blog post by paul irish.
Upvotes: 0