Navigation Bar Height and Functionality - css

So I'm looking at creating a navigation bar that'll sit at the top of my webpage and stick to it no matter where I scroll, but it always gets caught and disappears as I scroll away?
Not only that, but this is what happens when I hover over it:
Is it possible to also only have the darker background fill the actual black bar it sits inside?
This is the snippet from my style sheet as well:
body {
background-color: #ecf0f1;
margin: 0;
font-family: Arial;
}
header {
background-color: #333;
}
.navbar {
height: 5%;
overflow: auto;
margin: auto;
width: auto;
min-height: 60px;
top: 0;
text-align: center;
}
.title {
display: block;
}
.navbar ul {
list-style-type: none;
position: fixed;
top: 0;
padding: 0;
overflow: hidden;
}
.navbar li {
display: inline-block;
}
.navbar li a {
padding: 25px;
display: block;
height: 100%;
color: white;
text-decoration: none;
}
/* Change the link color to #111 (black) on hover */
.navbar li a:hover {
background-color: #111;
}
All help is greatly appreciated! First time playing around with CSS!
EDIT:
Here is the snippet of HTML that creates this header
<link rel="stylesheet" type="text/css" href="style/style.css">
<header>
<div class="navbar">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Contracts</li>
<li>Other</li>
</ul>
</div>
</header>

Fix the header...not the navbar or the menu.
body {
background-color: #ecf0f1;
margin: 0;
font-family: Arial;
}
header {
background-color: #333;
position: fixed;
top: 0;
width: 100%;
}
.navbar {} .title {
display: block;
}
.navbar ul {
list-style-type: none;
padding: 0;
margin: 0;
overflow: hidden;
}
.navbar li {
display: inline-block;
}
.navbar li a {
padding: 25px;
display: block;
height: 100%;
color: white;
text-decoration: none;
}
/* Change the link color to #111 (black) on hover */
.navbar li a:hover {
background-color: #111;
}
body {
height: 2000px; /* so you can see the header NOT moving */
}
<header>
<div class="navbar">
<ul>
<li class="hvr-underline">Home
</li>
<li>About Us
</li>
<li>Contracts
</li>
<li>Other
</li>
</ul>
</div>
</header>

Related

Nav bar will not move up to be even with the img at the top using CSS dreamweaver

I have a logo image on the upper left side of the site and want my nav to show on the upper right side of the site. The nav is showing on the right side of the page but instead of being parallel to the logo it is below it even thought the logo is on the left side. Any idea what I am missing in the code below that is preventing the nav from moving up.
#charset 'UTF-8';
html,
html * {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: arial, sans-serif;
<!-- font-size: 1vw;>
background: white;
}
img {
width: 100%;
max-width: 100%;
height: auto;
vertical-align: middle;
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
a, a:visited {
color: inherit;
}
header {
position: fixed;
padding: 1.5em;
top: 0;
left: 0;
width: 100%;
z-index: 1000;
}
.site-logo {
width: 30%;
max-width: 30%;
position: relative;
display: block;
}
.site-logo img {
width: 22em;
}
.logo {
opacity: 1;
}
.site-nav {
position: relative;
float: right;
z-index: 400;
top: 0;
left: 0;
display: block !important;
width: 68%;
padding: .75em 1em 0 0;
opacity: .95;
background: none;
}
.site-nav ul {
list-style-type: none;
margin: 0;
text-align: right;
}
.site-nav ul li {
display: inline-block;
margin-bottom: 0;
margin-left: 1.5em;
}
.site-nav ul li a {
font-size: .85em;
padding-bottom: .5em;
text-decoration: none;
letter-spacing: .15em;
text-transform: uppercase;
color: #000000;
-webkit-transition: color .3s;
transition: color .3s;
}
.site-nav ul li a:hover {
outline: none;
border-bottom: 1px solid black;
}
HTML
<header>
<!-- Logo -->
<a class="site-logo">
<img class="logo" src="images/SBI Logo.png" alt=""/>
</a>
<!-- Navigation Menu -->
<nav class="site-nav">
<ul>
<li>Home</li>
<li>Rooms</li>
<li>Gift Certificates</li>
<li>About Us</li>
<li>Things To Do</li>
<li>Contact Us</li>
<li>Blog</li>
</ul>
</nav>
</header>
enter image description here
You are getting bogged down in the style sheet and using EM too, it would be much easier for you to use PIXELS instead of EM to position your elements.
<style>
.mysitelogo
{
margin-top: 16px;
width: 458px;
height: 114px;
}
.mysitenav
{
float: right;
padding: 8px;
opacity: .95;
}
</style>
<header>
<!-- Logo -->
<img class="mysitelogo" src="logo.gif" alt="" />
<!-- Navigation Menu -->
<nav class="mysitenav">
<ul>
<li>Home</li>
<li>Rooms</li>
<li>Gift Certificates</li>
<li>About Us</li>
<li>Things To Do</li>
<li>Contact Us</li>
<li>Blog</li>
</ul>
</nav>
</header>
Using the code above you can get the layout you desire, THEN fine tune your layout in the stylesheet.
Some times it is easier to break the bigger problem down into basic parts.
Read this page for better understanding of using EM which is relative to FONT SIZE
https://www.w3schools.com/CSSref/css_units.asp

How to add css3 to your project mvc web application visual studio 2015

Problem
cannot add navigation menu to my project because css3 not need to
define why ?
it display with green lines in all css file why
How to solve this problem ?
my code
<head>
<link href="~/Content/menu.css" rel="stylesheet" />
</head>
<div class="grid">
<div class="grid__item">
<nav class="header">
☰ menu
<ul>
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
I create menu.css file in content folder i add following code :
css3
#import "compass/css3";
$base-font-size: 16px!default;
$base-line-height: 24px!default;
$base-spacing-unit: $base-line-height!default;
body {
background: grey;
color: #555;
}
.header {
width: 100%;
background-color: #4C8FEC;
height: $base-line-height * 2;
margin-top: $base-line-height;
}
a {
color: black;
text-decoration: none;
font-weight: bold;
&:hover {
color: white;
}
}
.current {
color: white;
}
.menu-icon1 {
display:inline-block;
width: 100%;
height: $base-line-height * 2;
color: black;
line-height: $base-line-height * 2;
text-align: center;;
}
nav ul, nav:active ul {
display: none;
position: relative;
padding: 0 $base-spacing-unit;
background: #4C8FEC;
width: 100%;
list-style: none;
}
nav li {
text-align: left;
width: 100%;
padding: 10px 0;
margin: 0;
}
nav:hover ul {
display: block;
}
/*MEDIA QUERY*/
// #include media-query(desk){
#media screen and (min-width: 600px) {
nav {
float: left;
.menu-icon1 {
display: none;
}
}
nav ul, nav:active ul {
display: inline;
padding: 0;
width: 100%;
}
nav li {
display: inline-block;
width: auto;
padding: 0 $base-spacing-unit;
line-height: $base-line-height * 2;
}
}
image to my problem

#media rule - force new line in NavBar and display previously right aligned links in this line but center aligned

I have a NavBar with my name left aligned(green background color), and then links to other pages which are right aligned(no background color). When re-sizing to less than 640px I need to move the right aligned links to a new line, and center all NavBar content. I cannot get the links to move to a second line.
HTML:
/* menu bar */
header{
background-color: #ffffff;
height: 60px;
margin: 0;
padding:0;
}
ul{
list-style-type: none;
margin: 0;
padding: 0;
display:block;
}
/* align right */
li{
float:right;
}
/*link formatting*/
li a{
display:block;
padding: 8px;
color:black;
text-align: center;
padding:10px 16px;
text-decoration: none;
font-weight: bold;
}
/* name with background color*/
li:last-child{
font-size: 34px;
background-color: #4aaaa5;
position:absolute;
float:left;
}
#media screen and (max-width: 640px) {
li:last-child{
font-size: 34px;
background-color: #4aaaa5;
position:absolute;
width: 100%;
text-align: center;
top: 0px;
}
}
<ul>
<li><a id="bottomlinks"href="index.html">About</a></li>
<li><a id="bottomlinks"href="portfolio.html">Portfolio</a></li>
<li><a id="bottomlinks"href="contact.html">Contact</a></li>
<li> Mark Ring</li>
</ul>
Here is a basic demo of what it looks like you're attempting to achieve. As you can see I've simplified the HTML and CSS a bit.
Hope it helps!
body {
margin: 0;
}
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
header {
text-align: center;
overflow: hidden; /* clearfix */
}
.brand {
display: block;
background-color: #4AAAA5;
line-height: 60px;
}
#media ( min-width: 640px ) {
header {
text-align: left;
height: 60px;
}
.nav {
float: right;
}
.nav li {
float: left;
line-height: 60px;
}
.brand {
display: inline-block;
padding: 0 1rem;
}
}
<header>
<a class="brand" href="#">Brand</a>
<ul class="nav">
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</header>
In your code you were absolute positioning the brand element on top of the other links (couldn't see them) and didn't undo the float (which kept them from stacking vertically).

CSS background-image in navigation (later hover)

I am a bit confused. I am not getting any image in my navigation, if I am using background-image in my CSS. If am doing it with HTML img tag I got an image, but if I try it with CSS I got nothing. :(
I tried it like this: https://stackoverflow.com/a/16194594/3701753
But nothing happens. I guess, there is something wrong with my CSS?!
Here is my code:
HTML:
<nav>
<ol>
<li class="home">
</li>
<li>Info
</li>
<li>Projects
</li>
<li>Contact
</li>
</ol>
</nav>
CSS:
/*******************************************
Links
*******************************************/
a:link {
font-family:'Iceland';
font-style: normal;
font-size: 30px;
font-weight: 700;
text-decoration: none;
color: #666;
}
a:visited {
color: #666;
}
a:hover {
color: #F90;
}
a:active {
}
/*******************************************
Navigation
*******************************************/
nav {
width: 100%;
bottom: 0;
left:0;
height: 60px;
position: fixed;
background-color: #333;
}
ol {
list-style: none;
text-align: center;
height: 100%;
}
li {
display: inline;
margin-right: 40px;
}
li a {
}
/*******************************************
Class
*******************************************/
.home {
background: url(../pics/home_button.png);
}
/*******************************************
ID's
*******************************************/
#main {
background-color: #C90;
width: 90%;
height: 84%;
margin: 5% auto;
}
Here is it in fiddle: http://jsfiddle.net/373Bc/2/
I made in icon and I would like to display it in the navigation!
There is some other issue which I am not able to get, may be with character code, indentation, or markup etc.
Because when I TidyUp your code in jsfiddle it works. I am not sure why is this happening.
Demo
.home {
background: url(http://explorelaromana.com/wp-content/themes/explorelaromana/images/home_icon.jpg);
width: 40px;
height: 32px;
line-height: 60px;
}
li {
display: inline-block;
margin-right: 40px;
}
Demo 2
Update the following CSS:
.home {
background:url (http://explorelaromana.com/wpcontent/themes/explorelaromana/images/home_icon.jpg) no-repeat;
display: inline-block;
height: 36px;
width: 43px;
vertical-align: bottom;
}
Hope this hepls. :)

How to vertically center links in a menu?

Here's the HTML :
<nav>
<ul class="menu">
<li class="li_pc">PC</li>
<li class="li_one">ONE</li>
<li class="li_ps3">PS4</li>
<li class="li_360">360</li>
<li class="li_ps3">PS3</li>
<li class="li_wiiu">WiiU</li>
</ul>
</nav>
and here's the CSS :
nav {
padding: 0;
margin: 0;
widht: 1200px;
height: 100px;
}
ul li {
display: inline;
font-family: Verdana, Geneva, sans-serif;
float: left; /* IE */
list-style-type: none;
}
ul li a {
display: block;
float: left;
width: 190px;
height: 60px;
padding: 0;
background-color: transparent;
color: white;
text-decoration: none;
text-align: center;
}
.li_pc a:hover {
background-color: #cc9a34;
}
.li_one a:hover {
background-color: #149a14;
}
.li_ps4 a:hover {
background-color: #040264;
}
.li_360 a:hover {
background-color: #9cce04;
}
.li_ps3 a:hover {
background-color: #0406b4;
}
.li_wiiu a:hover {
background-color: #5c12ac;
}
My goal is to vertically center the text in the cells. I'm using text-align:center; to center it horizontally, but when I use vertical-align:middle; it doesn't even move a pixel. I tried a lot of different ways but it always destroys the thing and makes the design look like my face on sunday morning.
How can I center these vertically please ?
Thanks in advance :)
If you anchor links are 60px tall
line-height:60px
should do it.
JSFiddle

Resources