Positioning header on the center - html

I've got little problems with my header that has to be symetrically perfect and I'm terrible at this so could you please tell me how to make the it positioned on the center and keep the margin between links?
How should it look like:
I'd also love to know how to make that underline on hover and the simple language switcher.
My code:
<nav id="nav">
<ul style="text-transform:uppercase">
<li>Strona główna</li>
<li>Portfolio</li>
<li><img src="logo.png"></img></li>
<li>O mnie</li>
<li>Kontakt</li>
</ul>
</nav>
CSS:
#nav {
position: absolute;
right: 0.5em;
top: 0;
height: 3em;
line-height: 3em;
margin-left:30%
}
#nav ul {
margin: 0;
}
#nav ul li {
display: inline-block;
margin-left: 0.5em;
font-size: 0.9em;
}
#nav ul li a {
display: block;
color: inherit;
text-decoration: none;
height: 3em;
line-height: 3em;
padding: 0 0.5em 0 0.5em;
outline: 0;
}

Removed a lot of margin and padding from your code.
Added position: relative;, text-align: center;, width: 100%; to #nav.
Also, Added margin:0; and padding:0; to *
Note: You didn't have img in li for some reason.
Change to this:
*{
margin:0;
padding:0;
}
#nav {
position: relative;
top: 0;
height: 3em;
line-height: 3em;
text-align: center;
width: 100%;
}
#nav ul {
margin: 0;
}
#nav ul li {
display: inline-block;
font-size: 0.9em;
}
#nav ul li a {
display: block;
color: inherit;
text-decoration: none;
height: 3em;
line-height: 3em;
padding: 0 0.5em 0 0.5em;
outline: 0;
}
For underline on hover.
Try this:
#nav ul li a:hover {
border-bottom: 3px solid #eee;
}
JSFiddle Demo

Add this to your css to make link underlined when hover.
#nav ul li a:HOVER{
text-decoration : underline;
}

Update your Nav class like below.
#nav {
position: absolute;
right: 0;
top: 0;
left:0;
margin:0px auto;
height: 3em;
line-height: 3em;
}
DEMO

You can center stuff on your webpage with the CSS property text-align:center;
As for the underline on hover? Just add an onhover event handler to it, then use document.getElementById("Makeanidforthestuffyouwantunderlined").class="Someclass";
in your javascript.
Finally, you can go to your CSS, and do this.
.Someclass{
text-decoration:underline;
}
Alternatively, some elements support the "hover" pseudo element.
p:hover{
text-decoration:underline;
}

Related

How to extend a navbar background, while keeping the elements in the center?

I want the blue of the navbar to extend across the screen, while the About, Updates, and Who am I? to stay in the middle? I want the background to remain a background so that it will change if I resize anything. I am fine with a different centering method, if that works better.
.centered {
display: flex;
justify-content: center;
}
#navbar {
background: #0099CC;
color: #FFF;
height: 51px;
padding: 0;
margin: 0;
border-radius: 0px;
}
*{
padding:0;
margin:0;
}
#navbar ul, #navbar li {
margin: 0 auto;
padding: 0;
list-style: none
}
#navbar ul {
width: 100%;
}
#navbar li {
float: left;
display: inline;
position: relative;
}
#navbar a {
display: inline-block;
display:flex;
line-height: 51px;
padding: 0 14px;
text-decoration: none;
color: #FFFFFF;
font-size: 16px;
text-align: center;
}
#navbar li a:hover {
color: #0099CC;
background: #F2F2F2;
}
#navbar label {
display: none;
line-height: 51px;
text-align: center;
position: absolute;
left: 35px
}
<div class="centered">
<nav id='navbar'>
<ul>
<li><a href='#'>Home</a></li>
<li><a href='#'>Updates</a></li>
<li><a href='#'>Who am I?</a></li>
</ul>
</nav>
</div>
You can add 100% width to #navbar to extend across the screen and change display & width properties for #navbar ul, like this
#navbar {
width: 100%;
}
#navbar ul {
display: flex;
width: fit-content;
}

How to make menu resizable without deforming it?

So I've created menu on my website, but when I resize windows it is going into other divs in same line. I tried various things but I didn't had any luck. My nav for menu is in another div for header with 2 more divs, for left, and right. I also pasted CSS of those stuff down there, they have class .icons and .logo, and main holder with .menuHolder.
Code
#primary_nav_wrap {
margin: 0.85% 0% 0% 26%;
width: 60%;
padding: 10px;
position: absolute;
min-width: 772px;
}
#primary_nav_wrap ul {
list-style: none;
position: relative;
float: left;
margin: 0;
padding: 0
}
#primary_nav_wrap ul a {
display: block;
color: #333;
text-decoration: none;
font-weight: 700;
font-size: 12px;
line-height: 32px;
padding: 0 15px;
font-family: "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif
}
#primary_nav_wrap ul li {
position: relative;
float: left;
margin: 0;
padding: 0
}
#primary_nav_wrap ul li:hover {
background: #ddd;
}
#primary_nav_wrap ul ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #fff;
padding: 0
}
#primary_nav_wrap ul ul li {
float: none;
width: 200px
}
#primary_nav_wrap ul ul a {
line-height: 120%;
padding: 10px 15px
}
#primary_nav_wrap ul ul ul {
top: 0;
left: 100%
}
#primary_nav_wrap ul li:hover > ul {
display: block
}
.icons {
float: right;
margin-top: 1.3%;
margin-right: 1.57%;
position: apsolute;
min-width: 53px;
}
.logo {
float: left;
position: apsolute;
/* min-width */
}
.menuHolder {
background-color: #fff;
width: 100%;
text-align: center;
margin: 0px auto;
padding: 0;
border-style: solid;
border-color: #CC0000;
border-width: 1px 0px 2px 0px;
height: 83px;
<nav id="primary_nav_wrap">
<ul>
<li class="current-menu-item">Index
</li>
<li>Blahblah
<ul>
<li>Blahblah2
</li>
<li>Blahblah3
</li>
<li>Blahblah4
</li>
</ul>
</li>
<li>Blahblah5
</li>
<li>Blahblah6
</li>
<li>Vaša pitanja i odgovori
<ul>
<li>Blahblah7
</li>
<li>Blahblah8
</li>
</ul>
</li>
<li>Blahblah9
</li>
<li>Blahblah10
</li>
<li>Blahblah11
</li>
</ul>
</nav>
if you want to adjust to the width of the window on window size change you have to use SASS, LESS and bootstarp. when you resize the window all that css needs to be rendered again so you would need to literally write a compiler for css and part of the bootstrap manually! therefore using bootstrap and media query would be easier and they are easy to learn.
It also adds value to you as a programmer.
Here's a nav I use on my web page. I set up a side bar to place my menu's in. It stays the same size whenever I resize my page. It might be a starting place for you.
nav {
position: fixed;
left: 0;
top: 0;
bottom: 0;
background: #E5E4E2;
width:275px;
padding: 10px;
}

Hover not working in css

I'm here to ask a question I know is simple, but I just can not get it to work. I want to change the background color of my li tag to a different color once a user hovers over it.
HTML:
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
CSS:
nav {
background-color: #333;
margin: 0;
overflow: hidden;
width: 100%;
text-align: right;
}
nav ul {
margin: 0;
padding: 0;
}
nav ul li {
display: inline-block;
list-style-type: none;
}
nav ul li a {
color: #aaa;
background-color: #333;
display: block;
line-height: 2em;
padding: 0.5em 0.5em;
text-decoration: none;
}
nav ul li:hover {
background-color: #666;
color: #000;
}
Any help will be greatly appreciated, thanks!
add an a to the hover and it works
nav {
background-color: #333;
margin: 0;
overflow: hidden;
width: 100%;
text-align: right;
}
nav ul {
margin: 0;
padding: 0;
}
nav ul li {
display: inline-block;
list-style-type: none;
}
nav ul li a {
color: #aaa;
background-color: #333;
display: block;
line-height: 2em;
padding: 0.5em 0.5em;
text-decoration: none;
}
nav ul li a:hover {
background-color: #666;
color: #000;
}
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
The reason it doesn't work is that there are links inside the li tags - <a> tags. Those take on their own color when hovering. So you'll have to define your desired color for li a:hover { color: ...}
Your styling for the anchor tag is interfering with your li:hover instructions.
You have to think of them as layers, especially when you're using them as block elements. The dimensions of the anchor tag are bigger than the ones of the li tag, hence you don't see the hover effect. I corrected your code. This works:
nav {
background-color: #333;
margin: 0;
overflow: hidden;
width: 100%;
text-align: right;
}
nav ul {
margin: 0;
padding: 0;
}
nav ul li {
display: inline-block;
list-style-type: none;
background-color: #333;
}
nav ul li:hover {
background-color: #666;
color: #000;
}
nav ul li a {
color: #aaa;
background: transparent;
display: block;
line-height: 2em;
padding: 0.5em 0.5em;
text-decoration: none;
}
Try to see, if you notice what I changed. This helps you to understand what was wrong in the first place. :)

Center logo in middle of navigation menu

I am looking to display my logo in the middle of my centered top navigational menu. As it stands right now, I have the logo sitting on top of it. Would it be easiest if I split the menu items into different containers and then used margins and padding to accomplish this? Or is there a more efficient way?
Here is a JS Fiddle showing my current scenario. JS Fiddle
Here is my current CSS:
.container {
width:960px;
margin:0 auto;
}
header, main{
display: block;
}
.container-narrow {
margin:0 auto;
width:640px;
}
h1.logo {
width:300px;
margin:0 auto;
text-indent:100%;
overflow:hidden;
white-space:nowrap;
}
body h1 {
background:url(http://placehold.it/300x80) no-repeat;
height:80px;
}
body section.menu,body header.top-section {
background:url(../img/menu-bg.png) repeat;
padding:60px 0;
}
body header.top-section {
padding:40px 0;
position:absolute;
top:0;
left:0;
width:100%;
z-index:50;
}
#menu_container {
letter-spacing: 2px;
font-family:'intro_regular', sans-serif;
font-size: 1.3em;
line-height: 1.3em;
position: fixed;
margin: 0;
/*margin-top: -70px;
position: relative;*/
z-index: 20;
left: 0;
right: 0;
text-align: center;
padding: 6px;
height: 40px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
box-sizing: border-box;
}
#menu_container .nav ul { list-style: none; overflow: auto; }
#menu_container .nav li { float: left; padding: 0.4em 0.8em; font-size: 0.9em; line-height: 1em; cursor: pointer; }
#menu_container .nav li a { text-decoration: none; text-transform: uppercase; }
#menu_container .nav li:hover a,
#menu_container .nav li.active a { color: #fff !important; }
#menu_container .nav li.contact_screen:hover a,
#menu_container .nav li.contact_screen.active a { color: white !important; }
#menu_container .nav li a { color: #000000; }
#menu_container .nav li a { transition: all 400ms; -webkit-transition: all 400ms; }
#menu_links { display: inline-block; }
#menu_button { display: none; color: white; cursor: pointer; text-align: right; padding: 0 0.8em; }
#menu_button i { font-size: 1.3em; margin-right: -0.3em; color:#bc9321;}
#menu_links li:first-child {}
I ran into this very scenario recently. I got it working by positioning the logo absolutely, then using :nth-child selectors to target the elements on either side of the logo and add margins to make room.
Here's the Fiddle
:nth-child is great, but you might want a fallback set of styles for older browsers .
Have you considered CSS3 display: flex?
http://css-tricks.com/snippets/css/a-guide-to-flexbox/
The issue I run into with this setup is that when you want to switch to smaller screens - this wouldnt work as well as your logo is still placed in the middle instead of allowing them stack block...
You could stick your logo class as an li in the middle.
<div id="menu_links" class="nav">
<ul>
<li class="home_link">Home</li>
<li class="menus_link">Menus</li>
<li class="logo">Restauraunt</li
<li class="contact_link">Contact</li>
<li class="reservations_link">Reservations</li>
</ul>
</div>
Then change h1.logo to li.logo.

Sub menu won't display

I have a hover drop down menu on my website. It displays ok until you hover over. The submenu appears but before you can click on a link, the sub menu vanishes.
Here is the HTML -
<div id="top-nav"><div id="nav">
<nav>
<ul id="menu" style="list-style-type: none;">
<li id="sub">Artists
<ul>
<li>Banks</li>
<li>Lil Silva</li>
<li>Frances and the Lights</li>
<li>Jim-E Stack</li>
</ul>
</li>
<li>Night</li>
<li>Info</li>
</ul>
</nav>
</div>
</div>
And here is the CSS -
#nav {
text-align:center;
list-style: none;
}
ul#menu {
background-color: #FFFFFF;
list-style: none outside none;
margin: 0 auto;
padding-bottom: 0px;
padding-top: 0px;
text-align: center;
width: 300px;
}
ul#menu:after {
content: "";
background-color: #FFFFFF;
height: 10px;
width: 100%;
display: block;
position: absolute;
left: 0;
margin-top: 20px;
}
ul#menu li {
float: left;
}
ul#menu li a {
color: #666666;
font-size: 12px;
margin: 0;
padding: 0px 35px;
text-decoration: none;
}
ul#menu li a:hover {
background-color: #ccc;
}
a.selected-page, ul#menu a.selected-page:hover {
background-color: #FFFFFF;
}
li#sub ul {
display: none;
position: absolute;
background-color: #FFFFFF;
z-index: 22222;
margin-top: 4px;
overflow: hidden;
}
li#sub ul li {
display: block;
float: none;
border-top-style: none;
border-width: 2px;
border-color: #FFFFFF;
text-align: left;
padding-top: 5px;
padding-bottom: 5px;
}
ul#menu li#sub:hover ul {
display: block;
}
ul#menu li#sub ul li:hover {
background-color: #FFFFFF;
}
What am I doing wrong? Any help is greatly appreciated!
the problem is the following line of your CSS code:
li#sub ul {
...
margin-top: 4px;
...
}
Just remove this margin-top and your drop down menu will work properly.
In your example there is a 4px margin space between the "Artists"-link and the drop down menu below. And if your cursors leaves the link and enters this "margin area", the browser interprets it as un-hovering the link - and hides the drop down.
Like dalucks said, remove the top margin from your CSS:
li#sub ul {
margin-top:0;
}
Also, reduce the left margin/paddings from the submenu UL and/or LI children. With the original large values (35px) the menu could be hovered over a lot of invisible space.
ul#menu li ul li a {
padding-left:5px;
}
Fiddle: http://jsfiddle.net/LXwTr/
Add Padding: 0 to this
li#sub ul {
padding: 0;
}
http://jsfiddle.net/tdQmE/