I'm having troubles coming up with a solution to styling my navigation. This is what I want:
And this is a link to what I have so far.
This is supposed to be two separate classes of links on one navigation bar. One set on the left for the logo and other default links, and on the right is for social. I'm just going to need help with the left side for now but I thought I'd explain even further.
On the left side, each link should be centered in their own little block with a border on the left and right being 1px white. On their hover state, the background of their "box" should be white. The logo should be first on the left.
I'm sorry that I'm not able to explain better, but I've done my best. The picture and the link to what I have so far should explain the most.
I think it would be better if the logo was in the CSS instead of the HTML??
CSS:
/* Navigation bar */
#navi {
font-family: Helvetica Neue: Condensed Bold;
font-size: 14px;
color: white;
text-transform: uppercase;
background-color: #1e416f;
height: 30px;
margin: 0 0 20px 0;
padding: 20px 0 0 0;
}
#navi a {
color: white;
margin: 0 0 0 20px;
height: 30px;
}
#navi a:hover {
background: white;
color: #1e416f;
}
HTML:
<!-- NAVIGATION -->
<div id="navi">
<img src="/imgs/navi/caul_white_nav.png">
Directories
Committees
Resources
About
</div>
You can try something like:
#navi img, #navi a {
float: left; /* float next to each other on the left hand side */
}
#navi a { /* use some padding to have some empty space */
padding: 5px;
border-right: 1px solid #ffffff;
}
#navi a:hover { /* on hover, background white on A tags */
background: #ffffff;
}
And than play untill it fits, with the right side you could do the same, inside the nav you can float it to the right. If you want to have a seperate DIV you should also float this #navi to the left and the #social to the right.
If you only use padding on an element (which is blocked) the text will always be centered because the padding left / right are the same.
TIP: If you use floats like this and you want an item to be on a new line. Normally it would be set next to the float. If you use a DIV after the item and do a clear: both; it will be on a new line.
I've written this using your design: http://jsfiddle.net/ninty9notout/v3658/
Just information on what is what here:
On the homepage, use: <h1 class="logo">...</h1> and on all other pages: <div class="logo">...</div>
.logo and #primary-nav are floated left to make them stick to the left side.
All the li and a tags are also floated to the left. Block elements are easier to style than inline elements.
#tools-nav is floated to the right so it sticks to the right side.
I've used text-indent: -9999px; to hide the text for the logo and the would-be icons in the #tools-nav - feel free to add the icons via background property. Set the widths for the icon anchors to whatever width your icons are + 20 (+10px on either side).
And that is that.
The HTML:
<div id="navi">
<h1 class="logo">Name of Site</h1>
<ul id="primary-nav">
<li>Directories</li>
<li>Committees</li>
<li>Resources</li>
<li>About</li>
</ul>
<ul id="tools-nav">
<li class="login">Log In</li>
<li class="email icon">Email</li>
<li class="twitter icon">Twitter</li>
<li class="search icon">Search</li>
</ul>
</div>
The CSS:
#navi {
height: 30px;
background: #1e416f;
font-size: 14px;
color: white;
text-transform: uppercase;
}
.logo {
margin: 0;
padding: 0;
float: left;
}
.logo a {
float: left;
margin: 2px 10px;
width: 36px;
height: 26px;
background: url(http://redsky.incredifull.com/imgs/navi/caul_white_nav.png) left top no-repeat;
text-indent: -9999px;
}
#primary-nav, #tools-nav {
list-style: none;
margin: 0;
padding: 0;
}
#primary-nav li, #primary-nav a,
#tools-nav li, #tools-nav a { float: left; }
#primary-nav a,
#tools-nav a {
color: white;
text-decoration: none;
padding: 0 10px;
border-right: 1px solid white;
line-height: 30px;
}
#primary-nav li:first-child a,
#tools-nav li:first-child a{ border-left: 1px solid white; }
#tools-nav { float: right; }
#tools-nav .icon a {
text-indent: -9999px;
}
#tools-nav .email a { /* image */ }
#tools-nav .twitter a { /* image */ }
#tools-nav .search a { /* image */ }
I think it's what you wanted. Enjoy :)
Use
<img src="/imgs/navi/caul_white_nav.png" style="float: left;">
Related
I want the navigation links: "about", "resume", "projects", and "contact" to line up horizontally in the navigation bar.
Why does this only work with display: inline-block?
It is my understanding that inline-block boxes allows these elements to be side by side. I need it to be inline-block instead of just inline because I want to size it to the nav bar's exact height.
What am I doing wrong?
Here is the HTML and CSS for my nav:
/* ----------------------------NAVIGATION SECTION-------------------------------- */
.headerContainer {
background-color: #000;
text-align: center;
height:60px;
margin-left: 600px;
margin-right: 600px;
font-family: 'Monda', sans-serif;
text-transform: uppercase;
position: fixed;
}
nav {
padding-left: 1000px;
padding-right: 1000px;
}
nav li {
list-style: none;
display: inline-block;
background-color: #000;
height: 40px;
padding-top: 20px;
width: 120px;
}
nav li:hover {
background-color: #e1e1e1;
-webkit-text-stroke: 2px #000;
}
a:link {
color: #fff;
text-decoration: none;
margin-left:25px;
margin-right:25px;
}
a:visited {
color: #fff;
}
a:focus {
color: #fff;
}
a:hover {
}
a:active {
color: #fff;
}
<!------------------------------NAVIGATION SECTION---------------------------------->
<header class="headerContainer">
<nav>
<ul>
<!-- you put the end tag ">" at the beginning of next line to get rid of whitespace between the links -->
<li>About</li
><li>Resume</li
><li>Projects</li
><li>Contact</li>
</ul>
</nav>
</header>
You have a massive amount of padding inside the nav element.
nav {
padding-left: 1000px;
padding-right: 1000px;
}
This doesn't leave very much space for the content to render in.
The li elements are laid out side by side until they run out of space, at which point they word wrap.
If you zoom out, you'll see the fit in one line.
If you look at the live demo in your question, with the very narrow frame, you will see everything squashed to the side.
Don't set a huge padding on the nav element.
i'm begginer in html and css and i'm building my first site based on my psd project, i just started making it and i can't get through one problem.
*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.grid {
margin: 0 auto;
width: 960px;
}
.primary-header {
position: relative;
background-color: #fff;
height: 85px;
}
.logo {
position: absolute;
top: 29px;
}
.primary-nav {
font-size: 12px;
font-weight: 700;
letter-spacing: .5px;
text-transform: uppercase;
}
.nav {
text-align: right;
}
.nav li {
display: inline-block;
vertical-align: top;
margin: 0 30px;
padding: 11px 30px;
}
.nav li:hover {
border: 1px solid #333;
border-radius: 5px;
background-color: #333;
color: #fff;
}
.nav li:last-child {
margin-right: 0;
}
border:1px solid #333;
border-radius:5px;
background-color:#333;
padding-bottom:10px;
color:#fff;
}
.nav li:last-child {
margin-right: 0;
}
<header class="primary-header">
<div class="grid group">
<a href="index.html">
<img src="http://i58.tinypic.com/2q2prah.png" class="logo" alt="logo">
</a>
<nav class="nav primary-nav">
<ul>
<li>O firmie</li>
<!--
-->
<li>Oferta</li>
<!--
-->
<li>Realizacje</li>
<!--
-->
<li>Kontakt</li>
</ul>
</nav>
</div>
</header>
and here's the effect i'm gonna reach:
So the problems are:
After pointing with cursor on menu element, padding-top and padding-bottom is too big, it should be 11px and right now it's propably 19px
According to margin-top in ".nav li" my nav should be vertically aligned, but it's a little bit too much into bottom, if i set margin-top: 0px;, there is still some white space above my nav, why?
After i point any menu element with cursor, all the menu elements move 1px to bottom, why?
Thanks for your answers, i was searching for answers for about 2 hours and i still didn't find it... please, help me..
Here's my best reply to your questions:
1) The padding is in addition to your text. For example, with Firebug I can see that OFERTA is measured as 15px tall. Add 11px to top and bottom and you get 37px. To get it to 11px, you're going to have to reduce the font-size and add minimal padding. If you don't care as long as the menu item isn't too big, then just lower the vertical padding in
padding: 11px 30px;
2) By default, the ul element has some margins. Set the margin to 0 for nav to remove it.
3) Previously, before hovering, the CSS rules state that the menu item has no border. On nav li:hover, the CSS adds a border, which increases the overall area and to compensate and stay in the center, the text moves slightly downward. A fix would be to add a border to the nav li.
Also,
border:1px solid #333;
border-radius:5px;
background-color:#333;
padding-bottom:10px;
color:#fff;
}
seems to be out of place. It's missing a opening brace and an identifier.
For #1, Try reducing the padding on .nav li from padding: 11px 30px to padding: 5px 30px
For #2, Add a float: left on your .logo and remove the position: absolute
For #3, Remove the border: 1px solid #333 on .nav li:hover
Number 1 renders fine on IE11 at my machine. Show 11px padding-top and -bottom. So this is working as it should. Maybe it is not desired?
Number 2 is caused by the margin on the UL, it's 12px.
.nav ul {
margin-top: 0px;
}
Number 3 is caused by the added border on hover. You need to use extra padding or set a transparent border to nav.li
.nav li {
display: inline-block;
vertical-align: top;
margin: 0 30px;
padding: 11px 30px;
border: 1px solid transparent;
}
I need some help. I am trying to make a horizontal navigation using only CSS and HTML. I don't want to have the menu labels as images, in case they change in the future. I have most of it working, but the issue is when I try to include an icon (image) for one of the LI. I want the icon to swap out as well. Here's my code so far:
CSS:
body {
padding: 50px;
margin: 0;
}
ul {
padding: 5px;
margin: 10px 0;
list-style: none;
background-color: #fff;
float: left;
clear: left;
}
ul li {
float: left;
display: inline; /*For ignore double margin in IE6*/
margin: 0 9px;
}
ul li a {
text-decoration: none;
float:left;
color: #111;
cursor: pointer;
font: 14px/22px "Segoe UI", Arial, Helvetica, sans-serif;
}
ul li a span {
margin: 0px 10px 0px -10px;
padding: 1px 4px 1px 14px;
position: relative; /*To fix IE6 problem (not displaying)*/
float:left;
}
ul.green li a:hover {
color: #fff;
background: url(images/green.png) no-repeat top right;
}
ul.green li a:hover span {
background: url(images/green.png) no-repeat top left;
}
ul.green li.home {
color: #111;
background: url(images/home-idle.png) no-repeat;
background-position: -1px;
padding-left: 18px;
}
ul.green li.home a:hover {
background: url(images/home-over.png) no-repeat -10px;
}
HTML:
<ul class="green">
<li class="home"><span class="home">Home</span></li>
<li><span>Archives</span></li>
<li><span>Rooms & Resources</span></li>
<li><span>Productivity</span></li>
<li><span>Get Training</span></li>
<li><span>FAQs</span></li>
</ul>
Like I said, here's what I am attempting do have happen:
Use CSS for the navigation (aside from the icon & background)
Change the background to a green, rounded corner rectangle (I used a
.png image for the background)
Change the Home icon from blue to white
Please let me know if anyone can help.
i have this menu:
<div class="nav">
<ul>
<li>HOME</li>
<li>AMORTECIMENTO</li>
</ul>
</div>
the normal apearance:
and this is the apearance when users hover the menu:
So, i dont know how to setup the css, assuming i have biggest names on menu like: "AMORTECIMENTO"
Any tips??
i have tried this, but on small names, the menu is cutting the background...
.nav ul li a{
display:block;
font-size:15px;
color:#000;
padding:5px 7px;
background:transparent;
text-decoration:none;
}
.nav ul li:hover{
background:url(../imagens/bola_fundo_menu.png) center no-repeat;
}
My intention is, when user hover the menu item, on the <li> background, apear the basketball, and on <a> tag, the background is going to #FFF but i have small and big names on menu, so i can't set width of <li> and <a> tags... i think
Here is a quick example using pseudo-elements: http://codepen.io/anon/pen/iwerJ
Using the exact HTML you originally posted, with CSS like this:
.nav {
background: #CCC;
font-family: Helvetica, Arial, sans-serif;
line-height: 48px;
margin: 50px auto 0;
width: 90%;
}
.nav ul:after {
clear: both;
content: '';
display: block;
}
.nav ul li {
float: left;
font-size: 14px;
list-style: none;
padding: 0 10px;
position: relative;
}
.nav ul li:hover:after {
/* Replace background with image */
background: #abc123;
/* Optionally remove radius */
border-radius: 30px;
content: '';
display: block;
position: absolute;
top: 50%; left: 50%;
margin-top: -30px;
margin-left: -30px;
height: 60px; width: 60px;
}
.nav a {
color: #333;
display: inline-block;
line-height: 180%;
padding: 0 4px;
position: relative;
text-decoration: none;
z-index: 1;
}
.nav li:hover a { background: #FFF; }
Just set a hover background. Eg:
div.nav li:hover{
background-image: url('basketball.jpg');
}
EDIT:
You've got a lot more issues than just a background image...
You need to vertically center your nav text set a min-width for the
nav cells so that the left and right of the ball aren't cut off
set a solid white background for the anchor tag so the text is actually visible on hover
set a z-index for the anchor tags that's greater
than the center image so that they are all clickable (right now you
can't click the link to the right of the center)
Good luck. I can't write all of that code out for you, but that should send you in the right direction.
on your nav class all you have to do is write your css like this:
.nav ul li:hover
{
background-image:url('yourimage.jpg');
}
To fix the cut-off images, you can simply put a min-width on your .nav li elements. Make sure the value is at least as wide as your background images.
You'll probably also want to add text-align: center.
I have a django app that has a horizontal navigation. For some reason I am having problems creating a drop down menu.
Have a look at both of these images
The first image shows the horizontal navigation. On the left side of the image, there is a menu.
The second image shows when I hover over Storage orders (This is the only link that has a drop down menu.) For some reason the right hand side of the tab seems a bit off. This is because the length of the tab for storage, delivery and collection are different due to the number of words. I want to try to make all of these three tabs the same length if possible.
Another problem that I have is the left hand side menu moves to the right when I move my curser over storage orders.
base_menu.html
<ul id="toc">
<li id="current"><span>Home</span></li>
<li><span>Create quote/order</span></li>
<li><span> Item Search</span></li>
<li><span>Storage orders</span><br/>
<ul class="subnav">
<li><span>Delivery orders</span></li><br/>
<li><span>Collection orders</span></li>
</ul>
</li>
<li><span>Delivery list</span></li>
<li><span>Collection list</span></li>
<li><span>Export for invoicing</span></li>
<li><span>Backup data</span></li>
<li><span>Help</span></li>
</ul>
<br/>
base.css
ul#toc {
height: 2em;
list-style: none;
margin: 0;
padding: 0;
}
ul#toc li{
background:#ffffff url(../images/tab.png);
float: left;
margin: 0 1px 0 0;
}
ul#toc span {
background: url(../images/tab.png) 100% 0;
display: block;
line-height: 2em;
padding-right: 10px;
}
ul#toc a {
color: #000000;
height: 2em;
float: left;
text-decoration: none;
padding-left: 10px;
}
ul#toc a:hover {
background: url(../images/tab2.png);
text-decoration: underline;
}
ul#toc a:hover span {
background: url(../images/tab2.png) 100% 0;
background-position: 100% -120px;
}
ul.subnav {
float:left;
display:none;
position:absolute;
}
ul#toc li:hover .subnav {
display:block;
}
EDIT: #Andres: If I make the change, you can see from the image below, the drop down tab needs to be lowered a bit more. Also, the collection tab is missing as well, but the good thing is the left hand menu does not shift to the right.
Update #Andres: I have removed the tag in the template has made the tab re-appear. Now using margin-top:10px seem to work. Now from the image below, I need to make sure my drop-down box can overlap the delivery header. And I think I may be done.
Try this:
ul#toc {
height: 2em;
list-style: none;
margin: 0;
padding: 0;
}
ul#toc li{
background:#ffffff url(../images/tab.png);
float: left;
margin: 0 1px 0 0;
position:relative;
}
ul#toc span {
background: url(../images/tab.png) 100% 0;
display: block;
padding-right: 10px;
}
ul#toc a {
color: #000000;
float: left;
text-decoration: none;
padding-left: 10px;
}
ul#toc a:hover {
background: url(../images/tab2.png);
text-decoration: underline;
}
ul#toc a:hover span {
background: url(../images/tab2.png) 100% 0;
background-position: 100% -120px;
}
ul.subnav {
float:left;
display:none;
position:absolute;
}
ul#toc li:hover .subnav {
display:block;
}
since your ul.subnav class is still in the flow of things when it pops up it shifts things on the bottom, if you position it absolutely, relative to the parent li it should fix things up.