I am trying to move the starting text in my nav menu more to the left and make the rest align up correctly in-between the gaps also i have noticed this dose not work on touch devices like the iPhone. I believe this is possible via the CSS sheet without having to use JavaScript.
Any help would be much appreciated
Many thanks
http://jsfiddle.net/p6Bj5/
HTML
<div class="navbar">
<ul id="nav">
<li>
Homepage
</li>
<li><a heref="#">About Us</a>
<ul>
<li>About</li>
<li>Allies</li>
<li>Rank</li>
</ul>
</li>
<li>
Members
</li>
<li>
Forums
</li>
<li><a heref="#">Stats</a>
<ul>
<li>In-Game Stats</li>
<li>Outfit Stats</li>
</ul>
</li>
<li><a heref="#">Media</a>
<ul>
<li>Downloads</li>
<li>Gallery</li>
<li>Videos</li>
<li>Live Streams</li>
</ul>
</li>
<li>
Events
</li>
</ul>
</div>
CSS
#charset "utf-8";
body {
font: 80%/1.4 Arial, Helvetica, sans-serif;
background-color:#000;
margin: 0;
padding: 0;
}
.navbar {
background-image:url(http://gbprojects.net/images/top_06.jpg);
width: 937px;
height: 48px;
line-height: 48px;
margin: 0 auto;
}
#nav{
list-style:none;
font-weight:normal;
margin: 0px;
line-height: 38px;
/* Clear floats */
float:left;
width:100%;
height: 38px;
font-size: 18px;
font-weight: bold;
/* Bring the nav above everything else--uncomment if needed.
position:relative;
z-index:5;
*/
}
#nav li{
float:left;
margin-right:40px;
position:relative;
}
#nav a{
display:block;
padding:10px;
color:#fff;
background: transparent;
text-decoration:none;
text-shadow: black 0.1em 0.1em 0.2em;
}
#nav a:hover{
color:#000;
text-decoration:none;
text-shadow: none;
}
/*--- DROPDOWN ---*/
#nav ul{
background: #02949d; /* Adding a background makes the dropdown work properly in IE7+. Make this as close to your page's background as possible (i.e. white page == white background). */
list-style:none;
position:absolute;
margin-top: -10px;
margin-left: -20px;
left:-9999px; /* Hide off-screen when not needed (this is more accessible than display:none;) */
line-height: 20px;
z-index: 100;
-moz-border-radius-topleft: 0px;
-moz-border-radius-topright: 0px;
-moz-border-radius-bottomright: 7px;
-moz-border-radius-bottomleft: 7px;
-webkit-border-radius: 0px 0px 7px 7px;
border-radius: 0px 0px 7px 7px;
-webkit-box-shadow: 0px 5px 3px 0px rgba(0, 0, 0, .25);
-moz-box-shadow: 0px 5px 3px 0px rgba(0, 0, 0, .25);
box-shadow: 0px 5px 3px 0px rgba(0, 0, 0, .25);
}
#nav ul li{
margin-left: -40px;
margin-right: 50px;
font-size: 12px;
padding-top:0px; /* Introducing a padding between the li and the a give the illusion spaced items */
float:none;
z-index: 100;
}
#nav ul a{
white-space:nowrap; /* Stop text wrapping and creating multi-line dropdown items */
z-index: 100;
}
#nav li:hover ul{ /* Display the dropdown on hover */
left:0; /* Bring back on-screen when needed */
z-index: 100;
}
#nav li:hover a{ /* These create persistent hover states, meaning the top-most link stays 'hovered' even when your cursor has moved down the list. */
background: transparent;
color: #000;
text-decoration:none;
z-index: 100;
text-shadow: none;
}
#nav li:hover ul a{ /* The persistent hover state does however create a global style for links even before they're hovered. Here we undo these effects. */
text-decoration:none;
z-index: 100;
margin-left: 20px;
text-shadow: none;
}
#nav li:hover ul li a:hover{ /* Here we define the most explicit hover states--what happens when you hover each individual link. */
background: transparent;
color: #fff;
z-index: 100;
margin-left: 20px;
text-shadow: none;
}
x;
line-height: 58px;
Your issue is that you are using a background image for the navigation bar. Because the words are different lengths you will need to go in and change the margins individually for each link. It is either that or add backgrounds to the ul and li which would have been the preferable method.
Try using like this.
.navbar {
background: url(http://gbprojects.net/images/top_06.jpg) 35px 0px no-repeat;
}
Don't give a huge margin to the elements for alignment.
Be specific to your background image for header because it seems no to be as perfect as should be.
You can keep it as plan background and put border-left or border-right properties to show a difference in between the list items. That is the good way of handling such cases. Hope it helps you.
Related
I have a anchor containing a span element containing my text. The span element has these attributes
border-bottom: 5px solid #59DFB8;
padding-bottom: 2px;
Now I want to create a shadow behind the border, but not the whole text. How would I do that without giving up on responsiveness?
.selected {
border-bottom: 5px solid #59DFB8;
padding-bottom: 2px;
box-shadow: 10px 10px 10px #59DFB8;
}
<div class="nav">
<ul>
<li><span class="selected">Home</span><span class="shadow"></span></li>
<li>Projects</li>
<li>About</li>
</ul>
</div>
Example:
The box-shadow property always uses its containing element's bounding box. You can't apply it to just part of an element, so you'll need to create an element specifically for the part that you want to have a shadow.
One solution would be to use pseudo-elements to create a child of the .selected element, and make that child look like an underline / bottom border. Then you can apply box-shadow to that.
Make your .selected element inline-block, so that its width is sized to its content. Then use the ::after pseudo-selector to create a block element inside of that, sized to the parent's width with a height of 5px and a solid background.
.selected {
/* so that its bounding box is only as wide as its contents */
display: inline-block;
}
.selected::after {
/* pseudo-elements must have content in order to render; give it a blank string */
content: '';
/* so it fills the parent horizontally */
display: block;
/* adjust to how tall you want the "bottom border" to be */
height: 5px;
/* color for the "bottom border" */
background: #59DFB8;
/* here's the shadow effect, adjust offsets and color as desired */
box-shadow: 10px 10px 10px #59DFB8;
}
Here is a full example, with simplified markup and some extra styles to make it look more like your example image.
ul {
list-style: none;
display: block;
background: #003447;
padding: 20px;
}
ul li {
display: inline-block;
padding-left: 20px;
padding-right: 20px;
}
ul li a {
font-family: Arial, sans-serif;
font-size: 20px;
color: #59DFB8;
text-decoration: none;
text-transform: uppercase;
}
ul li a::after {
content: '';
display: block;
margin-top: 5px;
height: 2px;
background: #59DFB8;
}
ul li a.selected::after {
box-shadow: 0px 0px 10px 1px #59DFB8;
}
ul li a:active::after,
ul li a:hover::after {
visibility: hidden;
}
ul li a.selected:active::after,
ul li a.selected:hover::after {
visibility: visible;
}
<ul>
<li>Home</li>
<li>Projects</li>
<li>About</li>
</ul>
You could do so with an :after or :before psudo-element.
.selected {
display: block;
float: left;
position: absolute;
width: 100%;
border-bottom: 5px solid #59DFB8;
padding-bottom: 2px;
box-shadow: 10px 10px 10px #59DFB8;
}
<div class="nav">
<ul>
<li><span class="selected">Home</span><span class="shadow"></span></li>
<li>Projects</li>
<li>About</li>
</ul>
</div>
I was going to expound but I see Woodrow beat me by a minute. ;p
Without seeing an example of how you want it to look I'm having to guess. The approach may depend on how subtle an effect you're going for. Here i've added a box shadow with a negative spread and semi-transparent fill:
a{text-decoration:none; color:#555;}
a:hover, a.active {
color:#000;
border-bottom: 5px solid #59DFB8;
padding-bottom: 2px;
box-shadow: 0 8px 10px -8px hsl(0, 0%, 40%);
}
.nav ul {margin:0; padding:0; display:flex;}
.nav li {margin:15px; list-style-type:none;}
<div class="nav">
<ul>
<li>Home</li>
<li>Projects</li>
<li>About</li>
<li>A Long One</li>
</ul>
</div>
Whatever I do I can't get the navigation to center.
I have a wrapper and the navigation bar has an underline across this div. The top of the buttons are rounded of so it just looks like they are coming out of the bottom border.
I've tried searching for a good way to center them. A lot of people use margin auto or margin 0 auto. Other people also use this in combination with display inline-block but then the border gets cut off from the nav buttons.
This is my HTML:
<div id="nav">
<ul>
<li>Home</li>
<li>About me</li>
<li>Portfolio</li>
<li>CV</li>
<li>Contact</li>
</ul>
</div>
The CSS:
#nav {
margin: auto;
color: #FFFFFF;
width: 100%;
border-bottom: 1px solid #000000;
}
#nav ul {
margin: auto;
padding-top: 6px;
padding-bottom: 8px;
padding-left: 5px;
list-style:none;
}
#nav li {
display: inline;
width: 120px;
margin:0;
padding: 10px 5px;
border-radius: 10px 10px 0px 0px / 10px 10px 0px 0px;
background : -webkit-gradient(linear, left top, left bottom, from(rgb(100,100,100)), to(rgb(132,132,132)));
background : -moz-linear-gradient(top, rgb(200,200,200), rgb(232,232,232));
}
#nav li:last-child {
border-right: none;
}
#nav a {
text-decoration: none;
color: #383838;
font-weight: bold;
font-size: 20px;
padding-right: 10px;
padding-left: 5px;
}
For the ease for you i've also put it in a js fiddle http://jsfiddle.net/ge702rna/
Really hope someone can help me out because i've got my hands tied up in my hair right now.
Probally i'm just doing something simple wrong.
Simply add text-align:center;
#nav {
color: #FFFFFF;
width: 100%;
border-bottom: 1px solid #000000;
text-align:center; /* <-- ADD THIS LINE */
}
I just change the width in
#nav {
margin: auto;
color: #FFFFFF;
width: 77%; //changed
border-bottom: 1px solid #000000;
}
Are you looking for this..DEMO
Im putting together a horizontal footer nav for a website that I am working on, but for the life in me I cannot get it to display correctly.
Basically what I am looking to achieve is for each menu item to be displayed with an image to the left go the link text with the text centred in relation to the middle of the image.
I know this is a simple problem, but everything I've tried to resolve the problem doesnt seem to work.
CSS
#footer-links{ border: 1px solid black; height:90px; width:100%;}
#footer-links .nav-bar { list-style:none;}
#footer-links .nav-bar li { display:inline; padding: 0 10px; }
#footer-links .nav-bar li a {
padding-left: 115px; /* Create padding on the left where the icon goes */
text-decoration: none;
text-transform: uppercase;
color: #333;
text-shadow: 1px 1px 1px #ccc;}
.nav-bar .nav-button-developments a { background:url("http://mulgraveproperties.co.uk/wp-content/uploads/2013/05/icon11.jpg") no-repeat 0px -2px transparent; }
.nav-bar .nav-button-news a { background:url("http://mulgraveproperties.co.uk/wp-content/uploads/2013/05/icon21.jpg") no-repeat 0px -2px transparent; }
.nav-bar .nav-button-contact a { background:url("http://mulgraveproperties.co.uk/wp-content/uploads/2013/05/icon31.jpg") no-repeat 0px -2px transparent; }
HTML
<nav id="footer-links">
<ul class="nav-bar">
<li class="nav-button-developments">Our Developments</li>
<li class="nav-button-news">News</li>
<li class="nav-button-contact">Contact Us</li>
</ul>
</nav>
Here is a link to the associated
http://jsfiddle.net/n420jmsw/
Any help would be greatly received.
I'm not sure to get it right but what about a float ? http://jsfiddle.net/n420jmsw/3/
#footer-links .nav-bar li { padding: 0 10px;float:left; }
Hi Please help me on this issue.
Issue: dropdown values of the menu is shown in other menu (it is not in-line with menu).
Example: Dropdown values of Home menu is Home-1, Home-2, Home-3 and it will shown under National parties menu. How can I show appropriately under the right menu
Demo: http://jsfiddle.net/shrikanth/Sv79m/
<div id="menu">
<ul>
< li>Home<ul>
<li>Home-1</li>
<li>Home-2</li>
<li>Home-3</li>
</ul></li>
<li ><a href="aboutus.html">National Parties<ul>
<li>BJP</li>
<li>Congress</li>
<li>CPM</li>
</ul></a></li>
<li><a href="services.html">Services<ul>
<li>TV</li>
<li>Cell</li>
<li>Radio</li>
</ul></a></li>
<li>Contact Us
<ul>
<li>India</li>
<li>USA</li>
<li>SAUS</li>
</ul>
</li>
</ul>
</div>
CSS
#menu {
width: 550px;
height: 35px;
font-size: 16px;
font-family: Tahoma, Geneva, sans-serif;
font-weight: bold;
text-align: center;
text-shadow: 1px 2px 1px #333333;
background-color: #8AD9FF;
border-radius: 8px;
}
#menu ul {
height: auto;
padding: 8px 0px;
margin: 0px;
}
#menu li {
display: inline;
padding: 20px;
}
#menu ul li a {
text-decoration: none;
color: #00F;
padding: 8px 8px 8px 8px;
}
#menu a:hover {
color: #F90;
background-color: #FFF;
}
#menu ul li ul{
display:none;
position:absolute;
top:31px;
background-color:red;
}
#menu ul li:hover ul{
display:inline-block;
height:auto;
width:135px;
}
#menu ul li ul:before{
content: '';
border-color: transparent transparent red transparent;
border-style: solid;
border-width: 10px; /* The border on the drop down box */
position: absolute;
top: -20px;
left: 37%;
margin-left:10px;
}
http://jsfiddle.net/Sv79m/1/
Give #menu li a position of relative:
#menu li {
display: inline;
padding: 20px;
position:relative;
}
Adjust a little the absolute positioning with left:0 :
#menu ul li ul{
display:none;
position:absolute;
top:51px;
background-color:red;
left:0;
}
Edit:
Also, to solve the overlapping links, add this:
#menu ul li ul li{
display:block;
padding:5px;
}
http://jsfiddle.net/Sv79m/2/
Also, you had some unclosed tags, I closed them and now it's much better:
http://jsfiddle.net/Sv79m/3/
<a href="aboutus.html">National Parties<ul>
^^CLOSE ME!
It's all down to the positioning of the containing element. If you use position: relative; it allows you to position elements absolutely inside of it.
Here's a tutorial on creating a dropdown navigation, it explains about the positioning and structure. This should help - CSS 3 navigation menu
So i have an issue with a CSS dropdown menu being displayed wrong in IE. In other browsers it works like it should.
<body>
<div id="container">
<header>
<div id="hlogo">
title
</div>
<nav id="hmenu">
<ul>
<li>
menu1
</li>
<li>
menu2
<div id="items" class="hiddenMenu">
submenu1
submenu2
submenu3
submenu4
</div>
</li>
<li>
menu3
</li>
<li>
menu4
</li>
</ul>
</nav>
</header>
<section id="container-body">
<div id="content">
</div>
</section>
</div>
So this is my complete HTML. It has a layout provided by the following css.
/* layout styles */
*{margin:0;padding:0;font-family:Arial;}
header{overflow:hidden;}
body{background-color:#cc3333;}
a {display: inline-block;font-weight: bold;text-decoration:none;}
footer {
display:block;
position:relative;
width:100%;
}
footer > #disclamer {
margin-left: auto;
margin-right: auto;
width: 200px;
padding-bottom:5px;
font-size:small;
font-weight: bold;
}
#container{
background-color:#ffffff;
margin:auto;
min-width:756px;
width:60%;
overflow:hidden;
border:solid 2px #666666;
margin-top:10px;
margin-bottom:10px;
box-shadow:0 1px 3px rgba(0,0,0,0.6);
}
#hlogo {float:left;height:105px;width:181px;padding:10px;}
#hlogo a{background-position: 0px 0px;float:left;display:inline;height:105px;text-indent:-999999em;width:181px;}
#hlogo a{background-image:url('../images/logo.png');background-repeat:no-repeat;overflow:hidden;}
#hmenu{margin-top:45px;padding:10px;}
nav {
list-style:none;
display:inline;
float:right;
}
nav ul{
list-style: none;
text-align:center;
background-color:#666666;
float:left;
}
nav ul li {
width:128px;
float:left;
display:inline-block;
}
nav ul li:hover{
background-color:#cc3333;
cursor:pointer;
}
nav ul li a {
color:#ffffff;
padding:10px;
}
nav ul {
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
cursor: pointer
}
section {margin:10px;}
#container > header {display:block;}
#container-body {
background-color:#ececec;
height:600px;
display:block;
overflow:auto;
}
#container-body > #content {
margin: 10px;
height:95%;
position:relative;
}
.hiddenMenu
{
position:absolute;
z-index: 150;
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
cursor: pointer;
width: inherit;
}
.hiddenMenu > a
{
position:relative;
text-align: left;
clear:both;
font-size:0.75em;
}
nav li .hiddenMenu > a
{
display:none;
}
/*nav li:hover .hiddenMenu > a
{
display:block;
}*/
nav li .hiddenMenu > a:hover
{
background-color:#cc3333;
cursor:pointer;
border: 1px black solid;
}
This is the full CSS.
This is the CSS i use. Now in firefox it works as it should. The menu is show when i hover the menu2 item. On IE it shows the first submenu item (submenu1) and then it is cleared so i can't even click it.
I can't see what i'm doing wrong so if you can help me i would appreciate it. Thanks!
edit: added code.
The header tag has an overflow:hidden attribute; if i set that to visible it will show the complete menu but will mess up my layout completely. Is there a way around it or am i doing something wrong?
Also, i have a jquery script to set the display on the menu to none/block accordingly but in IE if i hover on the submenu items the menu will still be hidden. Why does this happen?
In my experience IE gets a bit buggy when you don't set the positions of an absolute positioned object. Like top: 0 and left: 0 for instance.
Edit:
Also, parent of the absolute positioned object should have position: relative; if the position should be using the parent dimensions as a starting point.
Edit2:
li:hover doesn't work in IE6 I think. Can't remember about IE7. One of them will only accept a:hover, and browsers below maybe none of them. jQuery solves things like that though.
Edit3:
I don't know what the nav stuff is, I haven't jumped to HTML5 so I don't know if it's relevant later. But anyway I've made something that works of your code.
Script (jquery):
$(document).ready(function () {
$('#hmenu ul li').hover(function () {
$(this).children('div').css('display', 'block');
},
function () {
$(this).children('div').css('display', 'none');
});
});
CSS:
#hmenu {
list-style: none;
display: inline;
float: right;
}
#hmenu ul {
list-style: none;
text-align: center;
background-color: #666666;
float: left;
}
#hmenu ul li {
width: 128px;
float: left;
position: relative;
display: inline-block;
}
#hmenu ul li:hover {
background-color: #cc3333;
cursor: pointer;
}
#hmenu ul li a {
color: #ffffff;
padding: 10px;
}
#hmenu ul {
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
cursor: pointer
}
.hiddenMenu {
display: none;
position: absolute;
top: 60;
left: 0;
z-index: 150;
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
cursor: pointer;
width: inherit;
}
(sorry for the formatting, bit new to this, but you can apply source formatting in your editor I guess. I changed the navs to have the id and changed the HTML nav to be div. That's it.
HTML:
<div id="hmenu">
<ul>
<li>
menu1
</li>
<li>
menu2
<div id="items" class="hiddenMenu">
submenu1
submenu2
submenu3
submenu4
</div>
</li>
<li>
menu3
</li>
<li>
menu4
</li>
</ul>
</div>
You cannot have a tag named nav change it to div and try again.