Reputation: 302
So I've got a problem with a navigation bar. I've set its width to 100%. But I would like to see the end, because it's got rounded corners...
So like this: | (=======) |
Not like it's now: | (==========|
#nav {
height: 60px;
font-size: 30px;
line-height: 60px;
vertical-align: middle;
text-align: center;
background-color: #0080FF;
width: 100%;
border: 10px solid #16044E;
border-radius: 20px;
z-index: 1;
}
#nav ul {} #nav li {
display: inline;
text-align: center;
margin: 20px;
}
#nav a {
color: white;
text-decoration: none;
}
<ul id="nav">
<li><a href="">Home</a>
</li>
<li><a href="">Courses</a>
</li>
<li><a href="">Subjects</a>
</li>
<li><a href="">Sign Up</a>
</li>
<li><a href="">Log In</a>
</li>
</ul>
Upvotes: 3
Views: 59
Reputation: 1619
Add this to your #nav
box-sizing: border-box;
That will make your width: 100%;
apply to the border part as well.
Upvotes: 1
Reputation: 475
Change #nav
as follows:
Change width: 100%;
to width: auto;
Your #nav
should look like this:
#nav {
height: 60px;
font-size: 30px;
line-height: 60px;
vertical-align: middle;
text-align: center;
background-color: #0080FF;
width: auto;
border: 10px solid #16044E;
border-radius: 20px;
z-index: 1;
}
Upvotes: 0
Reputation: 14348
You can use calc
to reduce 10px
from the total width (10px
= border-width
) But you should try box-sizing:border-box
as the browser support for calc
is limited Caniuse
#nav {
height: 60px;
font-size: 30px;
line-height: 60px;
vertical-align: middle;
text-align: center;
background-color: #0080FF;
width: calc(100%-10px);
border: 10px solid #16044E;
border-radius: 20px;
z-index: 1;
}
#nav ul {
}
#nav li {
display: inline;
text-align: center;
margin: 20px;
}
#nav a {
color: white;
text-decoration: none;
}
<ul id="nav">
<li><a href="">Home</a></li>
<li><a href="">Courses</a></li>
<li><a href="">Subjects</a></li>
<li><a href="">Sign Up</a></li>
<li><a href="">Log In</a></li>
</ul>
Upvotes: 5
Reputation: 17471
You can use the calc()
CSS function with a callback in case you need to support older browsers, here is the current support, and you have to add this to your #nav
:
#nav{
width: 98%;
calc(100%-10px);
}
Another approach is changing the box-sizing
of the #nav
element, so the border will be part of the element width, you may have do update few rules in the CSS but it will work in IE8+, all mobile, and all modern browsers, here the caniuse:
#nav{
padding-left: 10px;
width: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
Upvotes: 1