CSS tabs menu looks ugly when changing browser-zoom - html

Please look at my CSS Tabs menu: http://jsfiddle.net/NoGo/3Spru/
It uses the YAML 4 CSS Framework form yaml.de (Edit 2019: not actively developed anymore)
The Tabs are: Home | Users | Map
My HTML:
<nav>
<div class="ym-wrapper">
<div class="ym-wbox">
<ul>
<li>
<a href="#">
<div>Home <i class="icon-home"></i></div>
<span>Go to Main Page</span>
</a>
</li>
<li class="active">
<a href="#" class="">
<div>Users <i class="icon-search"></i></div>
<span>Search User Accounts</span>
</a>
</li>
<li>
<a href="#">
<div>Map <i class="icon-globe"></i></div>
<span>Users near you</span>
</a>
</li>
</ul>
</div>
<div class="ym-clearfix"></div>
</div>
</nav>
The CSS:
header nav {
clear: both;
width:100%;
position:relative;
white-space: nowrap;
padding-top:10px;
border-bottom: 2px solid #CA278C;
}
header nav ul {
list-style: none;
padding:0;
margin:0;
display:inline;
}
header nav ul li {
display: inline-block;
border-top: 2px solid transparent;
margin: 0 5px -2px 0;
background-color: #f0f0f0;
border-bottom: 2px solid #CA278C;
line-height: 180%;
}
header nav ul li.active,
header nav ul li:hover {
border-top: 2px solid #CA278C;
border-bottom: 2px solid #fff;
background-color: #fff;
}
header nav ul li.active {
border-right: 2px solid #CA278C;
border-left: 2px solid #CA278C;
}
header nav ul li a {
display: inline-block;
padding: 5px 16px;
}
header nav ul li a div {
text-transform: uppercase;
font-weight: bold;
font-size: 16px;
}
header nav ul li a span {
font-size: 11px;
color: #999
}
header nav [class^="icon-"],
header nav [class*=" icon-"] {
vertical-align: baseline;
line-height: inherit;
opacity: 0.7;
}
My problem: When I change browser zoom, the bottom-line looks ugly. Is there a better way than working with margin-bottom: -2px on li elements?

I could get it to look a lot better by using subpixel positioning and setting the margin-bottom and border-width to -1.5px and 1.5px respectively. It looks fine here at jsFiddle - with minimal effort - on 100% up to somewhere close to 200%, and you could probably get it to look even better at other zoom levels by going further down the subpixel rendering path.
But then it dawned on me that you don't really need to have that bottom border on the inactive tabs, just set the margin-bottom on the tabs to 0px and then set the margin-bottom at the .active and :hover class to -2px. This will automatically look fine on any zoom level, as you won't have to worry about 'lineing up the lines' at all. Here's a jsFiddle for this approach.
header nav ul li {
display: inline-block;
margin: 0 5px 0 0;
border-top: 2px solid transparent;
background-color: #f0f0f0;
line-height: 180%;
position: relative;
}
header nav ul li.active,
header nav ul li:hover {
border-top: 2px solid #CA278C;
border-bottom: 2px solid #FFF;
background-color: #fff;
margin-bottom: -2px;
}

Related

Border full with but then different color for each item

Im trying to have a layout like this, with a full width gray border but then below the active item have a different border color:
enter image description here
But its not working. Do you know why?
https://jsfiddle.net/Ldye5qg8/
<div class="container">
<div class="nav">
<a class="active" href="">Item 1</a>
Item 2
</div>
</div>
Css
a{text-decoration:none;}
.nav{
border-bottom: 3px solid gray;
}
.nav a{
padding: 15px;
}
.nav .active{
border-color:yellow;
padding:20px;
}
Try this one. Hope it will work
EDIT: I used 5px bottom color in .nav. So, the whole .nav will use 5px bottom color. Then I used 5px in .nav a.active bottom color. The .nav a.active bottom color will be shown but on different lines. Hence I used margin-bottom: -5px to overlap .nav color.
.nav {
list-style-type: none;
padding-left: 0;
margin: 0;
border-bottom: 5px solid #ccc;
}
.nav a {
display: inline-block;
padding: 0 15px 0 15px;
margin-left: -4px;
text-decoration:none;
}
.nav a.active {
border-bottom: 5px solid yellow;
margin-bottom: -5px
}
<div class="container">
<div class="nav">
<a class="active" href="">Item 1</a>
Item 2
</div>
</div>
.nav .active {
border-bottom: 3px solid yellow;
padding: 20px 20px 1px 20px;
}
is not the same element, you need to bring for him border-style also to bottom.
Just change border color to border-bottom like this
.active {
border-bottom: 3px solid yellow;
}

How to make the a href fill the entire tab menu without losing the original size and shape?

I want to have the entire tab menu to be clickable. In order to do that, I need the "a href" to fill the entire tab but doing so I lose the exact size and shape I want. I'm trying to accomplish by adding the :not(#sub_menu ul il) to the main ul, il{} css styles but it throws the portions out of whack.
So how can I accomplish this in HTML & CSS? Also, the bottom border is still viewable, so how can I fix this as well? Thank you
Adding :not(#sub_menu ul li) to the main p, il settings.
Then increasing the padding by 5px to "10px 20px" in #sub_nav ul li #selected.
Home Page
<body>
<main>
<h3>Home</h3>
<nav id="sub_nav">
<ul>
<li id="selected">Home</li>
<li>Away</li>
</ul>
</nav>
</body>
Away Page
<body>
<main>
<h3>Away</h3>
<nav id="sub_nav">
<ul>
<li>Home</li>
<li id="selected">Away</li>
</ul>
</nav>
</body>
CSS
#sub_nav {
float: left;
width: 100%;
font-weight: bold;
padding-bottom: 5px;
border-bottom: 1px solid;
}
#sub_nav ul {
list-style: none;
padding: 0;
margin: 0;
}
#sub_nav ul li {
display: inline;
border: 1px solid black;
}
#sub_nav ul li a {
padding: 5px 15px;
color: inherit;
text-decoration: none;
border-width: 1px 1px 0px 1px;
}
#sub_nav ul li#selected {
border-bottom: 1px solid white;
}
main {
margin-bottom: 1px;
padding: 1px;
height: 4000px;
width: 80%;
border: 1px solid black;
float: left;
}
main ul {
margin: 10px;
padding: 10px;
}
main p, li {
margin: 5px;
padding: 5px;
}

Navigation and text for li item

I am currently trying to create a navigation bar where I have an medium sized image on top of the <li> tag with text underneath (similar to css-tricks).
I have tried background-image and also an img within li tag itself and still no joy.
My main goal is so that the user can click the icon and/or the text and it will still direct them to the correct page.
If you have any additional questions I am more than happy to assist.
nav#navBar img {
height: 80px;
margin-left: 80px;
}
nav#navBar {
background-color: white;
position: fixed;
top: 0;
left: 0;
right: 0;
height: 80px;
display: flex;
align-items: center;
box-shadow: 0 0 25px 0 black;
font-family: 'Nunito Sans', sans-serif;
font-variant: small-caps;
font-weight: 600;
}
nav#navBar * {
display: inline;
padding: 15px;
}
nav#navBar li {padding: 30px;}
nav#navBar li.blue:hover {border-bottom: 2px solid #33A1DE;}
nav#navBar li.red:hover {border-bottom: 2px solid #CC3232;}
nav#navBar li.green:hover {border-bottom: 2px solid #28AE7B;}
nav#navBar li.purple:hover {border-bottom: 2px solid #7A378B;}
nav#navBar li a {
color: black;
text-decoration: none;
}
<nav id="navBar">
<img src="#">
<ul>
<li class="green">ARTICLES</li>
<li class="blue">SNIPPETS</li>
<li class="red">MEMBERS</li>
<li class="purple">CONTACT</li>
</ul>
</nav>
You have to put a background image on the li tag and use padding to push the text down.
nav#navBar li.green {background:url(image.jpg) no-repeat; padding-top: 30px;}

Why doesn't this CSS style my elements correctly?

I'm trying to have an inline-block navigation bar. When someone hovers over the li, I want it to change background colors - simple enough.
It appears as though my code causes the background to be off about 2 inches.
Here is the offending code -
css-
#mainNav {
width: 100%;
background:#bbb;
border-right: 2px solid #777;
border-left: 2px solid #777;
border-bottom: 2px solid #555;
}
#mainNav ul li {
display: inline-block;
line-height:40px;
font-size: 20px;
padding: 0 15px 0 15px;
border-right: 2px solid #777;
}
#mainNav ul li.active {
background:#aaa;
}
#mainNav ul li:hover {
background:#aaa;
}
html-
<div class='container_12'>
<nav id="mainNav">
<ul>
<li class='active'><a href='#'>Home</a></li>
<li><a href='#'>Games</a></li>
<li><a href='#'>Forums</a></li>
</ul>
</nav>
</div>
Screenshot:
Give margin-left to li will solve the problem.
DEMO
It should also be :
#mainNav ul li:active {
background:#aaa;
}
Just like hover is coded out. Still not sure about the original question though.

two hyperlink inside a <li> list item

How to insert two hyperlinks side by side inside an li item?
In the html code below, I need to put "login" and "register" link side by side separated by a "|". What modification is required in the below code to accomplish the task.
Thanks.
The html file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"></html>
<html>
<head>
<link href="styledel.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="navcontainer">
<ul id="navlist">
<li>Home</li>
<li>The Tool
<ul id="subnavlist">
<li>Secondary Link</li>
</ul>
</li>
<li>Tutorials &AMP; FAQs</li>
<li>Login | Register</li>
</ul>
</div>
</body>
</html>
The css file:
#navcontainer
{
border-right: 1px solid #000000;
padding: 0px; /* menu look*/
font-family: 'Courier New',Courier,monospace;
background-color: #d4cfcf;
}
#navcontainer ul
{
list-style: none;
margin: 0px;
padding: 0px;
border: none;
}
#navcontainer li
{
border-bottom: 1px solid #90bade; /*separator*/
margin: 0;
}
#navcontainer li a /*menu */
{
display: block;
padding: 5px .3em 5px .3em;
border-left: .3em solid #1958b7;
border-right: .3em solid #508fc4;
color: #004963;
text-decoration: none;
}
#navcontainer li a:hover /*behavior on hover */
{
background-color: #ffffff;
color: #ad0000;
}
#navcontainer li li /*sub menu*/
{
border-top: 1px solid #90bade;
border-bottom: 0;
margin: 0;
font-family: 'Courier New',Courier,monospace;
font-size: 13px;
}
# navcontainer li li a /* sub menu */
{
padding: 4px 4px 4px 15px;
color: #5b6f7b /* light slate color: #00788a color of text */
}
/* navigation menu end */
Thanks a ton.
UAs the code is now, the links should be side by side. If they arn't, it's because they don't have enough space. This could be because you're setting a width that's too small, or the margins and paddings reduced the available space.
If you want the list items to be in one line, you use display:inline on them
#nav li{display:inline}
ul{list-style:none;} /* because you don't want a list with inline items to have bullets. */
Try switching a little of the CSS out from the <a> tag to the <li> element instead, like below, where you remove display:block from the li a and move the border-decoration to the li. Then, where you have #navcontainer li li, remove the border-decoration by setting border-left:0px and border-right:0px;
#navcontainer li
{
padding: 5px .3em 5px .3em;
border-left: .3em solid #1958b7;
border-right: .3em solid #508fc4;
border-bottom: 1px solid #90bade; /*separator*/
margin: 0;
}
color: #004963;
text-decoration: none;
}
#navcontainer li a:hover /*behavior on hover */
{
background-color: #ffffff;
color: #ad0000;
}
#navcontainer li li /*sub menu*/
{
border-top: 1px solid #90bade;
border-bottom: 0;
margin: 0;
font-family: 'Courier New',Courier,monospace;
font-size: 13px;
border-left:0px;
border-right:0px;
}
#navcontainer li li a /* sub menu */
{
padding: 4px 4px 4px 15px;
color: #5b6f7b /* light slate color: #00788a color of text */
}
/* navigation menu end */​