I'm not sure why my hover effect isn't working on my navigation bar, and I was wondering if anyone can point out where I've went wrong?
Here is my html and css:
<div id="nav">
<a class="selected" href="Property%20Advisor.html">Home</a>AboutContact Us
</div>
#nav {
position: fixed;
top: 0;
width: 100%;
height: 7%;
margin: 0;
text-align: center;
font-family: rosario, sans-serif;
background-image: -moz-linear-gradient(#44597F, #021840);
background-image: -ms-linear-gradient(#44597F, #021840);
background-image: -webkit-linear-gradient(#44597F, #021840);
background-image: linear-gradient(#44597F, #021840);
}
#nav a {
display: inline-block;
font-size: 100%;
padding-top: 1%;
padding-left: 2%;
padding-right: 2%;
margin: 0;
border: 0;
padding-bottom: 1%;
color: white;
text-decoration: none;
margin-right: 1px;
background-image: -moz-linear-gradient(#44597F, #021840);
background-image: -ms-linear-gradient(#44597F, #021840);
background-image: -webkit-linear-gradient(#44597F, #021840);
background-image: linear-gradient(#44597F, #021840);
}
#nav homeHover a:hover, onCLick {
background-color: #44597F;
color:orange;
}
.selected {
background-color: #000000;
color: orange;
}
Here is a JSfiddle of my code:
http://jsfiddle.net/VDmh8/1/
http://jsfiddle.net/VDmh8/3/
You need to change:
#nav homeHover a:hover, onCLick {
background-color: #44597F;
}
to:
#nav a:hover {
background-color: #44597F;
background-image: none;
}
because for one, #nav homeHover a:hover would select a hovered upon a element within an element with tag name homeHover within #nav, which won't target the a elements that you want.
Also, you need to reset the background-image property that you set for your unhovered a.
You just messed up your CSS target.
JSFiddle
You're trying to change #nav a I presume, so all you need to do is use the CSS selector - #nav a:hover.
Setting a background gradient for both your nav and link elements is generally a bad idea. The two gradients will attempt to fit into different sized spaces and clash together. Instead, try creating a nav with a gradient, and then making transparant buttons above the nav, so you don't need to specify a new gradient. This is a bit difficult to explain, so check below:
For the navigation button, just leave out the background entirely when it isn't being hovered, and it will show the #nav color behind, like here.
As a more general example:
#nav{
/* gradients here! */
}
.button /* not hovered */
{
/* Don't set a background color - it will be transparant. */
}
.button:hover /*the same button when it's hovered. */
{
background: #123456;
}
(Also PS: never use something like height: 7%; for the nav. It ends up scaling improperly.
Use a definite height, like height: 48px.
If you really want to make a responsive website, a CSS Media Query would be better suited in this situation.
Why do you have a HomeHover in your css? That way, it looks for #nav, then a HomeHover tag inside the nav and then the anchor tag to match.
nav a:Hover will do.
The background-image seems to be drawn over the background-color. You need to set the background-image to something else on the hover.
nav a:hover {
background-color: #44597F;
background-image: none;
}
Fiddle
Related
So I have a vertical navbar, and I haven't been able to center the tabs. The text is too far off to the right, and when I hover over it, the highlighted box doesn't extend to the margins. My code is below:
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Matthew H. Goodman</title>
<link href="style2home.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<ul id="nav">
<li>HOME</li>
<li>CV</li>
<li>RESEARCH</li>
<li>CONTACT</li>
</ul>
</body>
</html>
CSS:
#nav {
margin-top: 200px;
left: 0;
width: auto;
height: auto;
border-radius: 10px;
position: absolute;
background-image: url("http://www.diiiz.com/variant/Argent%C3%A9.jpg");
}
#nav li {
position: relative;
list-style: none;
padding: 15px;
width: auto;
}
#nav li a {
position: relative;
display: block;
text-decoration: none;
font-size: 15px;
font-weight: bold;
color: white;
text-align: center;
}
#nav li a:hover {
color: #778899;
background-color: black;
}
Browsers, and some CSS resets add default rules to elements like UL/OL to keep style-less html elements looking consistent.
ul#nav { padding-left: 0; }
I would recommend using a CSS reset (normalize, eric meyer's reset, etc) to allow you to start from scratch.
Use chrome/firefox/ie11 dev tools (F12, or right click and inspect element), go to the element in the window and hover over it to see the margin/padding rules. Scroll down the CSS rules on the right side to find where they are being applied Or click on 'computed styles' to see all the rules.
For the hover states,
you need to apply your hover to the li and handle the color separately
#nav li:hover { background-color: black; }
#nav li:hover a { color: #778899; }
You also need to add
#nav { overflow: hidden; }
to maintain your border-radius
You have some padding being applied to your #nav element you can fix it by adding:
#nav {padding:0px;}
To make the background cover the entire line add more padding to a and remove padding from the li with the current markup that will do the trick.
li {padding:0px;}
a {padding:15px;}
you can insted add a hover state to the li element but that but that will cause some problems with being able to click the a element correctly.
I have a few images with which I'm using background-color.
HTML:
<nav id="mainNav">
<ul id="buttons">
<li><img src="https://dl.dropboxusercontent.com/s/tqbyzi5pm97d95m/Message.png"/></li>
</ul>
</nav>
CSS:
#mainNav {
opacity: 0.75;
filter: alpha(opacity=75);
position: relative;
}
#mainNav ul {
margin: 0 auto;
padding: 0;
position: absolute;
left: 0;
right: 0;
}
#mainNav li {
display: inline;
margin: 0.3em;
}
#mainNav img {
height: 1.5em;
background-color: blue;
border: none;
}
#mainNav a:link, #mainNav a:visited, #mainNav a:hover, #mainNav a:active {
font-size: 1em;
font-weight: bold;
text-decoration: none;
color: blue;
}
#mainNav a.active {
text-decoration: none;
}
No issues occur on my standard setup, OS X Safari Version 7.0.6 (9537.78.2) but in iOS 7 Safari, border lines appear.
For example: and
What can I do to avoid this?
Thanks!
EDIT: Note how it appears on other sides of images, how is that?
I really suspect you did not resized/cropped properly your .png images.
A reason this might happen is that you'll need to double-check your .png images. Means, open them again in your favorite editor and remove the half-transparent borders that usually occur resizing an image and saving it as png with alpha transparency.
Also try to add to your img:
vertical-align: middle;
and make sure to take a look at <img> inside <a> gets blue border
While I'm still not certain what exactly caused the issue, it is probably just a rendering glitch rare among browsers.
The solution I am using is simply replacing the used (.png) images with SVGs and background-color with CSS' ability to color .svg images. The code for this is CSS:
svg {
fill: blue;
}
or replacing an actual color with currentcolor for making the fill same color as the parent element.
Try adding the border style to the image and set it to zero.
See How remove border around image in css?
I saw a nice video on youtube about making transional gallery (http://www.youtube.com/watch?v=4sVTWY608go). I tried to do the slider right..
Now, I want to make a change. I want to give the first image a different width say(530px) and the other images(40px). Then when a user hover on any other images(not img no.1) the width of image no.1 change to be like(40px) and the hovering one (530px). how can I do that.
Here is my code:
HTML
<div class="divSlider">
<ul>
<li id="slideImg1"></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
=========
CSS
===SET THE WIDTH OF THE IMAGES IN a
.divSlider li a{
width: 30px;
height: 500px;
text-decoration: none;
color: black;
display: block;
border: 2px solid gray;
border-radius: 5px;
}
=== image no.1 width
#slideImg1 a{
width: 540px;
}
=== when hovering on all the images except image no.1
.divSlider li a:hover{
width: 520px;
}
=== here is the problem I don't know how can I change it's width when user hover on other images
#slideImg1 li a:hover{
width: 20px;
}
Any help
TIA
If I understand your question correctly, here is one possible solution:
Demo Fiddle
The trick here is to set the CSS :hover to key off of the wrapping element, and then overwrite it with more specificity.
CSS:
/* initial setup */
li{ display: inline-block;}
a {
display: block;
width: 40px;
height: 150px;
background: url(http://www.placehold.it/150x150) no-repeat;
-webkit-transition: .3s;
transition: .3s;
}
#slideImg1 a { width: 150px;}
/* hover states */
.divSlider:hover #slideImg1 a {width: 50px;}
.divSlider ul #slideImg1 a:hover {width: 150px;}
a:hover { width: 150px;}
I think this would be done with javascript in a very easy way, so there's no point in trying to accomplish it with only css.
You would only need to add onMouseOver attributes and then do whatever you want with the javascript code.
I can post the code if you ask for it.
I am trying to get my navigation bar to have a current page indicator and I have researched every article possible, as well as, followed exact examples, but it still will not work.
I am using a sprite image of only two images. The image is width of 480, height 40 with each image at width 240, height 40. One side is blue and the other side is yellow.
I want to have the off-state to be the blue side, and then have the hover, active and current state be the yellow side. However, I dont care to have an active state at the moment.
So, my question is: my off state(blue side), hover state(yellow side) work perfect. I just need my current state(yellow side) to work. So, when you click on the menu item the image stays yellow.
I apologize for any horrible coding, as this is my first attempt
This is a portion of what I have for my html: (I will use just one of the three menu items, profile.)
<body bgcolor="CEB86C"; class="profile">
<div id="navigation">
<ul>
<li><a class= "news" href="news.html" title"news"></a></li>
<li><a class="profile " href="index.html" title"profile"></a><li>
<li><a class= "about" href="about.html" title"about"></a><li>
</ul>
</div>
Here is the CSS:
#navigation ul {
list-style: none;
text-align: center;
}
#navigation li {
display: inline;
}
#navigation li a {
text-indent: -5000px;
display: inline-block;
height: 40px;
}
#navigation li a.profile {
width: 240px;
background: url(images/profile.jpg);
text-decoration: none;
}
#navigation li a.profile:hover {
background: url(images/profile.jpg);
background-position: -240px;
text-decoration: none;
}
#navigation li a.profile:current {
background: url(images/profile.jpg);
background-position: -240px;
background-repeat: no-repeat;
text-decoration: none;
}
I appreciate any input and thank you in advance!
Assuming that you change the class on the body depending on which page you are on then you can just modify the last css declaration to read:
.news #navigation li a.news,
.profile #navigation li a.profile,
.about #navigation li a.about {
background:url(images/profile.jpg);
background-position: -240px;
background-repeat: no-repeat;
text-decoration:none;
}
Edit - if you have 3 separate images then you could do something like:
.news #navigation li a.news {
background:url(images/news.jpg);
background-position: -240px;
background-repeat: no-repeat;
text-decoration:none;
}
.profile #navigation li a.profile {
background:url(images/profile.jpg);
background-position: -240px;
background-repeat: no-repeat;
text-decoration:none;
}
.about #navigation li a.about {
background:url(images/about.jpg);
background-position: -240px;
background-repeat: no-repeat;
text-decoration:none;
}
Try #navigation li a.accountbutton:active instead of :current
Follow-up from another post here: IE7 li bullet or number shown outside of div
In the previous post, the li element outside the div was fixed, but now I have another IE7 bug with the hover element. Since the hover element can not be set through the , how do I fix this one?
P.S. Obviously I've been having some trouble with the hasLayout bug in IE, so it someone was to give a nice explanation it would be appreciated.
Again everything works in firefox, etc.
The screenshots:
The code:
#create_request ol {
width: 339px;
}
#create_request li {
display: list-item;
line-height: 23px;
background-color: #E3E3E3;
list-style: decimal;
list-style-position: inside;
padding-left: 25px;
padding-top: 5px;
}
#create_request li.alternate {
background-color: white;
}
#create_left li:hover {
width: 356px;
background: url('/images/list_add.png') 100% 100% no-repeat;
background-color: #B0B0B0;
cursor: pointer;
}
Unfortunately, that's not possible without bringing in another element in the <li>. The incorrect list-style-position behaviour occurs in IE6/7 when the <li> element get hasLayout. You want to totally avoid hasLayout on the element. The width is one of the hasLayout triggers.
I suggest to put a <span> in the <li> (yes, sorry if you would cry)
<li><span>Item</span></li>
and change the li:hover style as follows
#create_left li:hover {
background: #B0B0B0;
cursor: pointer;
}
#create_left li:hover span {
display: block;
width: 356px;
background: #B0B0B0 url('/images/list_add.png') 100% 100% no-repeat;
}
This way the span controls the width of the <li> without giving it hasLayout. You only need to remove padding-top: 5px; from the <li>'s CSS and counteract it with line-height, otherwise the <span> will not get the full height.
Make it if necessary an IE6/7 conditional stylesheet.
I believe you need to declare "list-style-position" in the rule for your OL tag:
#create_request ol {
list-style-position: inside;
}