I was working on web project, then a requirement came that I should add a top-level menu to my site. So I did a search and I found a menu from this URL http://www.webdesignerdepot.com/2012/08/create-a-stunning-menu-in-css3/.
But when I added the required css files & font, then menu was displayed out of the layout as follow:-
So can anyone advise on how I can do the following :-
To expand the menu horizontally to cover the whole screen .as for the top blue-colored area.
to have it exeactly below the blue-colored top area.
Reduce the menu width, and have it same as the breadcrumb.
Thanks
the css for the menu is :-
.clearfix {
clear: both;
}
.wrap {
width: 940px;
margin: 4em auto;
}
nav {
background: -webkit-gradient(linear, center top, center bottom, from(#fff), to(#ccc));
background-image: linear-gradient(#fff, #ccc);
border-radius: 6px;
box-shadow: 0px 0px 4px 2px rgba(0,0,0,0.4);
padding: 0 10px;
position: relative;
}
.menu li {
float: left;
position: relative;
}
.menu li a {
color: #444;
display: block;
font-size: 14px;
line-height: 20px;
padding: 6px 12px;
margin: 8px 8px;
vertical-align: middle;
text-decoration: none;
}
.menu li a:hover {
background: -webkit-gradient(linear, center top, center bottom, from(#ededed), to(#fff));
background-image: linear-gradient(#ededed, #fff);
border-radius: 12px;
box-shadow: inset 0px 0px 1px 1px rgba(0,0,0,0.1);
color: #222;
}
/* Dropdown styles */
.menu ul {
position: absolute;
left: -9999px;
list-style: none;
opacity: 0;
transition: opacity 1s ease;
}
.menu ul li {
float: none;
}
.menu ul a {
white-space: nowrap;
}
/* Displays the dropdown on hover and moves back into position */
.menu li:hover ul {
background: rgba(255,255,255,0.7);
border-radius: 0 0 6px 6px;
box-shadow: inset 0px 2px 4px rgba(0,0,0,0.4);
left: 5px;
opacity: 1;
}
/* Persistant Hover State */
.menu li:hover a {
background: -webkit-gradient(linear, center top, center bottom, from(#ccc), to(#ededed));
background-image: linear-gradient(#ccc, #ededed);
border-radius: 12px;
box-shadow: inset 0px 0px 1px 1px rgba(0,0,0,0.1);
color: #222;
}
.menu li:hover ul a {
background: none;
border-radius: 0;
box-shadow: none;
}
.menu li:hover ul li a:hover {
background: -webkit-gradient(linear, center top, center bottom, from(#eee), to(#fff));
background-image: linear-gradient(#ededed, #fff);
border-radius: 12px;
box-shadow: inset 0px 0px 4px 2px rgba(0,0,0,0.3);
}
#font-face {
font-family: 'IconicStroke';
src: url("~/fonts/iconic/iconic_stroke.eot");
src: local('IconicStroke'),
url("~/fonts/iconic/iconic_stroke.svg#iconic") format('svg'),
url("~/fonts/iconic/iconic_stroke.otf") format('opentype');
}
.iconic {
color:inherit;
font-family: "IconicStroke";
font-size: 38px;
line-height: 20px;
vertical-align: middle;
}
a.iconic:hover {
color:inherit;
}
My advice! Use firebug(an addon of firefox). Click on the menu and it will open all the css. Try changing them dynamically and chk the changes instantly. It even gives you the file where you need to make changes.
Apart from that what john said is right. Using fluid layout(%) is better than rigid(px). So when you say you need Menu to be of size of page then just make it 100%.
Happy Coding!
Related
I'm taking a coding class and we were making a navigation bar with clickable links. The problem is mine wouldn't work at all. I added position: relative; and top: 0; so that way the buttons would move down after clicking and also removed the box-shadow after clicking on the link. It doesn't seem to do anything. Does anyone know what the problem might be? Sorry if my question doesn't make any sense.
body {
margin: 10%;
font-family: Tahoma, Verdana, Geneva, sans-serif;
}
nav {
overflow: hidden;
width: 43%;
margin: 0 auto;
padding-bottom: 1em;
}
nav ul {
list-style-type: none;
/* Step 2: Remove bullets */
}
nav ul li {
float: left;
/* Step 3: Float li's left to line up horizontally */
}
/* Psuedoclass Class Selectors - State of links LVHA */
nav a:link {
/* Default state of link */
display: block;
/* Step 4: Gives anchor tag structure */
width: 6em;
/* Increases width of links and makes all buttons a standard width */
border: 2px solid rgb(175, 175, 175);
text-align: center;
text-decoration: none;
padding: .5em 1em;
/* Gives breathing room between content and inside of border */
margin: 0 5px;
border-radius: 6px;
background-color: rgb(190, 190, 190);
color: white;
text-shadow: #666 .1em .1em .1em;
/* Color, right, bottom, blur */
box-shadow: rgba(0, 0, 0, .5) 0 5px 3px;
/* Color, right, bototm, blur */
/* Sets position of each button to relative and sets positions to zero */
position: relative;
top: 0;
}
nav a:visited {
border: 2px solid rgb(175, 175, 175);
color: white;
}
nav a:hover {
background-color: #fdca00;
border-color: #fda700;
}
nav a:active a:focus {
/* Moves button 3px down and removes shadow on click */
top: 3px;
box-shadow: rgba(0, 0, 0, .5) 0 0 0;
}
<nav>
<ul>
<li>Men</li>
<li>Women</li>
<li>Kids</li>
<li>SALE</li>
</ul>
</nav>
The problem lies with this selector: nav a:active a:focus
It translates to an anchor element with focus inside an anchor element that's active inside a nav element. You don't want that. You want a list with two separate selectors, both originating from the nav element:
nav a:active, nav a:focus {}
This addresses both the active (currently being clicked) and focused (no other element has been selected yet) states of the element.
body {
margin: 10%;
font-family: Tahoma, Verdana, Geneva, sans-serif;
}
nav {
overflow: hidden;
width: 43%;
margin: 0 auto;
padding-bottom: 1em;
}
nav ul {
list-style-type: none;
/* Step 2: Remove bullets */
}
nav ul li {
float: left;
/* Step 3: Float li's left to line up horizontally */
}
/* Psuedoclass Class Selectors - State of links LVHA */
nav a:link {
/* Default state of link */
display: block;
/* Step 4: Gives anchor tag structure */
width: 6em;
/* Increases width of links and makes all buttons a standard width */
border: 2px solid rgb(175, 175, 175);
text-align: center;
text-decoration: none;
padding: .5em 1em;
/* Gives breathing room between content and inside of border */
margin: 0 5px;
border-radius: 6px;
background-color: rgb(190, 190, 190);
color: white;
text-shadow: #666 .1em .1em .1em;
/* Color, right, bottom, blur */
box-shadow: rgba(0, 0, 0, .5) 0 5px 3px;
/* Color, right, bototm, blur */
/* Sets position of each button to relative and sets positions to zero */
position: relative;
top: 0;
}
nav a:visited {
border: 2px solid rgb(175, 175, 175);
color: white;
}
nav a:hover {
background-color: #fdca00;
border-color: #fda700;
}
nav a:active, nav a:focus {
/* Moves button 3px down and removes shadow on click */
top: 3px;
box-shadow: rgba(0, 0, 0, .5) 0 0 0;
}
<nav>
<ul>
<li>Men</li>
<li>Women</li>
<li>Kids</li>
<li>SALE</li>
</ul>
</nav>
This is my website. The nav bar is causing me horrendous problems. Last night my friend told me it was dropping down and I just don't know how to fix it:
http://i60.tinypic.com/23iigpi.png
So I removed the width and reduced the text on some buttons which is depressing for me.
Anyway, now I want my smaller nav bar to centre in the middle of my white block. Does anyone know the best way?
http://www.simplypsychics.com/null/index-test.html
I have tried:
and modifying various positioning in the CSS but nothing seems to work.
This is my CSS for the nav:
#nav {
position: absolute;
top: 98px;
left:15px;
float: left;
list-style: none;
background-image:url(../images/menubanner.png);
background-color: #f5c3fd;
border-radius:7px;
-webkit-box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.05);
-moz-box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.05);
box-shadow: 1px 3px 1px rgba(0, 0, 0, 0.05);
}
#nav li {
float: left;
}
#nav li a {
display: block;
padding: 8px 13px;
text-decoration: none;
font-weight: bold;
color: #494949;
border-right: 1px solid #fceaff;
}
#nav li a:hover {
color: #822e8e;
}
#nav .home-icon1 {
background: url(../images/icon-home.png) no-repeat center;
width: 39px;
height: 34px;
background-color: #494949;
color: #f5c3fd;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
position: relative;
border-right: 1px solid #fceaff;
float: left;
padding: 0;
list-style: none;
}
#nav .home-icon1 a:hover {
background: url(../images/icon-home.png) no-repeat center;
width: 39px;
height: 34px;
background-color: #494949;
color: #f5c3fd;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
position: relative;
border-right: 1px solid #fceaff;
float: left;
padding: 0;
list-style: none;
}
#nav .home-icon2 {
background: url(../images/icon-findapsychic.png) no-repeat left;
padding: 0px 0px 0px 15px;
}
#nav .home-icon3 {
background: url(../images/icon-psychicreadings.png) no-repeat left;
padding: 0px 0px 0px 25px;
}
#nav .home-icon4 {
background: url(../images/icon-bookareading.png) no-repeat left;
padding: 0px 0px 0px 22px;
}
#nav .home-icon5 {
background: url(../images/icon-aboutus.png) no-repeat left;
padding: 0px 0px 0px 30px;
}
#nav .home-icon6 {
background: url(../images/icon-help.png) no-repeat left;
padding: 0px 0px 0px 14px;
}
and this is my HTML:
<div id="nav" style="margin:0 auto !important;">
<li class="home-icon1" onclick="window.location.href='http://www.simplypsychics.com/'"></li>
<li class="home-icon2">FIND A PSYCHIC READER</li>
<li class="home-icon3">PSYCHIC READINGS</li>
<li class="home-icon4">BOOK A READING</li>
<li class="home-icon5">FIND OUT MORE</li>
<li class="home-icon6">HELP/FAQ</li>
</div>
Also if the nav bar looks awful for you like it did my friend please let me know! :(
On parent (#headerwhiteback) set:
text-align: center;
Then on #nav, remove:
position: absolute;
float: left;
And add this CSS:
#nav {
display: inline-block;
}
#nav::before {
content: "";
clear: both;
}
Also, to your liking: add margin-top: on #nav (25px seems ok) and make padding-top: on next element, #headertextbottom, much smaller (20px seems ok).
This is just a quick fix for your header. Please remember: CSS looks horrific here and looks set to be rewritten from scratch or only cause you more and more trouble. Good luck!
If the nav bar is more-or-less a set width (#nav looks to stay at 840px) then you can set left:50% and margin-left:-420px (-420 px because it's half the width of the navbar, and we want to move it towards the left). This should work because you've already set the navbar to be positioned absolutely.
You'll have to remove this from the #nav div though: style="margin:0 auto !important;"
Inline style and !important is doubly bad!
I have an upper menu with the following CSS:-
nav {
background: -webkit-gradient(linear, center top, center bottom, from(#fff), to(#ccc));
background-image: linear-gradient(#fff, #ccc);
border-radius: 6px;
box-shadow: 0px 0px 4px 2px rgba(0,0,0,0.4);
padding: 0 10px;
position: relative;
}
.menu li {
float: left;
position: relative;
list-style-type: none;
/*background: url('img/denim.png');
font-family: 'Droid Sans', sans-serif;*/
}
.menu li a {
color: #444;
display: block;
font-size: 12px;
line-height: 5px;
padding: 6px 12px;
margin: 8px 8px;
vertical-align: middle;
text-decoration: none;
}
.menu li a:hover {
background: -webkit-gradient(linear, center top, center bottom, from(#ededed), to(#fff));
background-image: linear-gradient(#ededed, #fff);
border-radius: 12px;
box-shadow: inset 0px 0px 1px 1px rgba(0,0,0,0.1);
color: #222;
}
/* Dropdown styles */
.menu ul {
position: absolute;
left: -9999px;
list-style: none;
opacity: 0;
transition: opacity 1s ease;
}
.menu ul li {
float: none;
}
.menu ul a {
white-space: nowrap;
}
/* Displays the dropdown on hover and moves back into position */
.menu li:hover ul {
background: rgba(255,255,255,0.7);
border-radius: 0 0 6px 6px;
box-shadow: inset 0px 2px 4px rgba(0,0,0,0.4);
left: 5px;
opacity: 1;
}
/* Persistant Hover State */
.menu li:hover a {
background: -webkit-gradient(linear, center top, center bottom, from(#ccc), to(#ededed));
background-image: linear-gradient(#ccc, #ededed);
border-radius: 12px;
box-shadow: inset 0px 0px 1px 1px rgba(0,0,0,0.1);
color: #222;
}
.menu li:hover ul a {
background: none;
border-radius: 0;
box-shadow: none;
}
.menu li:hover ul li a:hover {
background: -webkit-gradient(linear, center top, center bottom, from(#eee), to(#fff));
background-image: linear-gradient(#ededed, #fff);
border-radius: 12px;
box-shadow: inset 0px 0px 4px 2px rgba(0,0,0,0.3);
}
Currently when the menu is displayed above an icon , the icon will occur above the menu text as follow:-
So is there a way to force the menu to be displayed above any text and icons ?
Thanks
Use Z-index to a high level on the menu and set the background color to solid white on the .menu li class as shown below:
nav {
background: -webkit-gradient(linear, center top, center bottom, from(#fff), to(#ccc));
background-image: linear-gradient(#fff, #ccc);
border-radius: 6px;
box-shadow: 0px 0px 4px 2px rgba(0,0,0,0.4);
padding: 0 10px;
position: relative;
z-index: 1000;
}
.menu li {
float: left;
position: relative;
list-style-type: none;
/*background: url('img/denim.png');
font-family: 'Droid Sans', sans-serif;*/
z-index: 1000;
}
.menu li:hover ul {
/*background: rgba(255,255,255,0.7);*/
background: rgba(255,255,255,1); /* use this to make the background solid white */
border-radius: 0 0 6px 6px;
box-shadow: inset 0px 2px 4px rgba(0,0,0,0.4);
left: 5px;
opacity: 1;
z-index:1000;
}
You need to change the background-color opacity to 1 block out the rear elements.
.menu li:hover ul {
background: rgba(255,255,255,1);
...
I am trying to get different 's to look differently, depending on the context. For example, in my html I have
<li> Home </li>
<li> Types of Insurance </li>
<li> Insurance Basics </li>
<li> Customer Center </li>
<li> About </li>
and in my css I have
.navlink : link
{
display:block;
width:120px;
text-align:center;
padding:10px;
text-decoration:none;
color:#FFFFFF;
}
.navlink : hover
{
background-color:#ADD8E6;
}
.navlink : visited
{
background-color:#ADD8E6;
}
But this is not working (the links appear unstylized). How would I fix this?
There must be no space before or after the :.
You need to get rid of the space before and after the colon (:).
You can also minimize your code by doing this:
.navlink {
// styling for unclicked link
}
.navlink:hover, .navlink:visited {
// styling for hover/visited state
}
I'm combining hover and visited because the only change you've made is the color, and it's the same for both.
Demo.
#nav{
float: left;
display: block;
font-size: 16px;
/*font-weight: bold;*/
font-family: 'Georgia', serif;
}
#nav>li{
display: block;
float: left;
line-height: 36px;
padding-right: 10px;
margin-left: 3px;
margin-right: 3px;
background: url(../img/nav-bullet.png) no-repeat center right;
}
#nav li>a:first-letter {
font-family: 'YataghanRegular', 'Georgia', serif;
font-size: 20px;
}
#nav li>a{ /* Parent Menu without hover*/
text-decoration: none;
color: #000000;
/*color: #CC3700; 606060*/
padding: 0px 10px 0px 10px;
display: block;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
#nav li:last-child{
background: none;
}
#nav>li:hover>a,
#nav>li.current-menu-item>a{/* Parent menu color with hover */
/*color: #eee;
background: #363636;*/
color:#000000;
background: #cce4ff ;
/*font-size: 12px;*/
/*background: -webkit-gradient(linear, left top, left bottom, from(#000000), to(#353535));
background: -moz-linear-gradient(top, #000000, #353535);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#353535', GradientType=0);*/
/*text-shadow: 0 -1px rgba(0, 0, 0, 0.7);*/
-webkit-box-shadow: 0px 1px 2px rgba(0,0,0,.5);
-moz-box-shadow: 0px 1px 2px rgba(0,0,0,.5);
box-shadow: 0px 1px 2px rgba(0,0,0,.5);
}
Try This..
How can I create a button style like that of the "Sign in" button on hotmail?
It looks like it uses some css3 gradient. Styles and state similar to screen shot for hover, active, etc.?
Can somebody provide some example code? Thx!
http://jsfiddle.net/9bahD/ play more with colors, but you never know if it will work in all browsers
for more buttons http://www.webdesignerwall.com/demo/css-buttons.html#
Log in
.button {
display: inline-block;
zoom: 1; /* zoom and *display = ie7 hack for display:inline-block */
*display: inline;
vertical-align: baseline;
margin: 0 2px;
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
font: 14px/100% Arial, Helvetica, sans-serif;
padding: .5em 2em .55em;
text-shadow: 0 1px 1px rgba(0,0,0,.3);
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-radius: .5em;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.button:hover {
text-decoration: none;
}
.button:active {
position: relative;
top: 1px;
}
.bigrounded {
-webkit-border-radius: 2em;
-moz-border-radius: 2em;
border-radius: 2em;
}
.medium {
font-size: 12px;
padding: .4em 1.5em .42em;
}
.small {
font-size: 11px;
padding: .2em 1em .275em;
}
/* blue */
.blue {
color: #d9eef7;
border: solid 1px #0076a3;
background: #0095cd;
background: -webkit-gradient(linear, left top, left bottom, from(#00adee), to(#0078a5));
background: -moz-linear-gradient(top, #00adee, #0078a5);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00adee', endColorstr='#0078a5');
}
.blue:hover {
background: #007ead;
background: -webkit-gradient(linear, left top, left bottom, from(#0095cc), to(#00678e));
background: -moz-linear-gradient(top, #0095cc, #00678e);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0095cc', endColorstr='#00678e');
}
.blue:active {
color: #80bed6;
background: -webkit-gradient(linear, left top, left bottom, from(#0078a5), to(#00adee));
background: -moz-linear-gradient(top, #0078a5, #00adee);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0078a5', endColorstr='#00adee');
}
Gradient buttons with states (active, hover): http://webdesignerwall.com/tutorials/css3-gradient-buttons