I have a css image rollover that is supposed to display a couple of buttons. It uses one image for 'normal' mode, one for 'hover' mode and one for 'active' mode. The three images are part of one large image file. I have implemented this method before on a different project and it worked fine, but for this project I cant seem to get the rollover effect working. My code is below:
<div class="homealertbox"><h1 class="homealert">The Worlds Best Marketplace For Buying & Selling Websites</h1>
<div class="addbuttons">
<span class="displace">Buy</span>
<span class="displace">Sell</span>
</div>
My CSS is below:
a.buy {
display: block;
width: 160px;
height: 40px;
float:left;
background:url('http://localhost/img/buy.png');
background-position: 0 0;
}
a.buy:hover {
background:url('http://localhost/img/buy.png');
background-position:0 -40px;
}
a.buy:active {
background:url('http://localhost/img/buy.png');
background-position:0 -80px;
}
.displace {
position: absolute;
left: -5000px;
}
a.sell {
display: block;
width: 160px;
height: 40px;
background: url('http://localhost/img/sell.png') 0 0 no-repeat;
float:right;
}
a.sell:hover {
background: url('http://localhost/img/sell.png') 0 -40px no-repeat;
}
a.sell:active {
background: url('http://localhost/img/sell.png') 0 -80px no-repeat;
}
I think the problem is to do with the nested div tags but I am not fully sure. Can somebody help please? Also, I apologize in advance if the code isnt formatted properly in this post.
Your code worked for me. The only this I changed to test in my local machine was the URL of CSS image backgrounds. I created 2 images with 2 button backgrounds each and saved each as sell.png and buy.png.. I changed the localhost/... background path in CSS to where I had saved them.
Check if your image path / url is correct and your images has the correct button backgrounds in correct locations. These are my images. My Buy image
Working Demo
Related
My site actually works okay in other browsers but when I checked in IE6, there is a problem. In my global navigation, I clicked this certain page. For example, I clicked ABOUT ME page. My global navigation changes its image when the page is active. Like it has a different color from inactive pages. In IE6, when I'm in the current page, ABOUT ME, the current image in the global navigation is different. Say, it's CONTACT US. But when hovered, the image that appears is correct.
This is the snippet of CSS:
.cat-item-5 {
float: left;
display: inline;
width: 162px;
height: 48px;
text-indent: -30000px;
background: -639px 0 url(images/menu.png) no-repeat;
}
.cat-item-5 a {
display: block;
width: 162px;
height: 48px;
background: -639px 0 url(images/menu.png) no-repeat;
}
.cat-item-5 a:hover,
.cat-item-5.current-cat a {
background: -639px 0 url(images/menu_o.png) no-repeat;
}
Hope you can help me, thanks!
IE6 has really really bad CSS support. It also has some nasty little bugs, of which you've been tripped up by one.
The bug is that when you have a double-class selector like .cat-item-5.current-cat, IE6 will only see the first of those classes, so it acts as if the selector is just .cat-item-5.
There's no good way around this bug. The only solution is to add another class to the relevant elements, and select that instead.
Your only other option is to simply drop support for IE6.
When Googling this hurdle, it came up with a ton of info about how to apply css and different static buttons as rollovers, when using an image as a button in a form.
My question is, how would you go about changing the button for each mouse event (on the button) and if you are using ONE image for all states?
For example... I have the following HTML for my button
<input type="image" id="login_submit" name="login_submit" src="button_login.png" />
and seperate to this I have the following CSS that I used before...
#login_submit a {
outline: none;
text-indent: -5000px;
display:block;
margin-left: auto;
margin-right: auto;
width: 141px;
height: 36px;
background: url("button_login.png") 0 0 no-repeat;
}
#login_submit a:hover {
background-position: -141px 0;
}
#login_submit a:active {
background-position: -282px 0;
}
now obviously it won't work at the moment... so how would I go about it? I'm looking for a more 'pure' CSS solution so no JS to brighten the day.
or should I stick with having 2/3 separate buttons for each state?
Well the main problem seems to be that you are trying to style an anchor that is a child to "#login_submit" instead of just "#login_submit", try this:
#login_submit {
outline: none;
text-indent: -5000px;
display:block;
margin-left: auto;
margin-right: auto;
width: 141px;
height: 36px;
background: url("button_login.png") 0 0 no-repeat;
}
#login_submit:hover {
background-position: -141px 0;
}
#login_submit:focus {
background-position: -282px 0;
}
Good luck,
Leo
I had this problem too, but just solved it.
By using an input type="image" and adding a 1x1px blank (transparent) .png or .gif to the src of the form element. Then using CSS for setting the background as the double (or, in the above case, triple) rollover image. The form element uses the blank .png as image, but beneath it lies the CSS handled background image, showing a beautifully working rollover with submit button functionality across its height and width.
=)
Code is taken directly from my situation:
HTML:
<div class="formrow">
<input id="send" type="image" src="../blank.png" name="Submit" onclick="submit" alt="Send" />
</div>
CSS:
#send
{
height: 25px;
width: 107px;
overflow: hidden;
display: block;
float: right ;
background: url('../images/style/button-send.png');
}
#send:hover
{
background-position: 0 -25px;
}
I hope this helps. =)
By the way, for me this approach took care of the problems mentioned by svict4 as well. =)
I am trying to do a little optimization on my website and it has brought me to what seems to be a quite common topic but I haven't been able to find a problem quite like mine.
What I had. A image sprite (foggy/clear) and text on top of it. When you hovered over the image it could become clear, when you hovered over the text it would highlight and turn blue. (The image would remain clear)
What I want. To reduce the sprite into one image (rather than two in one), as it is the largest file on my main page and 57% of my load time is spent on images.
What I have done:
1) Gone from a sprite to just one clear image.
2) Created a new 'foggy-img' div container, placed it on top of the image, white with opacity: 0.15
3) Created a new div 'img-text' container for the text to put it outside the 'foggy-img' so the opacity doesn't effect it and have got it nicely place where it should be.
The Problem: It is small, the see-through box has replaced the sprite nicely and works. The text also highlights nicely. But. When one hovers over the text the see-through box becomes 'foggy' again.
Is there any way to keep the 'foggy-box' clear when hovering over the text which is in a separate div?
The HTML:
<div id="photo-feature">
<a href="services.html">
<div id="img">
<div id="photo-fog"></div>
<div id="photo-text"><h3>Learn More...</h3></div>
</div>
</a>
</div>
The CSS:
#photo-feature a { text-decoration: none; }
#photo-feature #img { margin: 4px 5px 0 4px; width: 565px; height: 283px; background: url(images/photo-feature.png) 0 0; }
#photo-feature #img #photo-fog { height: 100%; background-color: #fff; opacity: 0.15; }
#photo-feature #img #photo-fog:hover { opacity: 0; }
#photo-feature #img #photo-text { position: absolute; margin-top: -34px; margin-left: 428px;}
#photo-feature #img #photo-text h3 { float: left; display: inline; color: #fff; }
#photo-feature #img #photo-text h3:hover { color: #0066cc; text-decoration: underline; }
You could use adjacent siblings selector.
(further details)
It doesn't work in older browsers though (guess which).
You would have to swap the ordering of your HTML a bit. Basically put the text first then use something like this:
#photo-text:hover + #photo-fog { // Do something
Right now you'd not be able to set the hover on the H3, but why not just style up the h3 rather than the #photo-text element then it would work fine.
Edit: Beautifully colour co-ordinated js fiddle for you to take a look at: http://jsfiddle.net/will/Gt8KX/
Hope that helps :)
I’ve been asked to create a CSS (non-HTML5) based site that has a filled div with a cutout that shows an image underneath it.
There are additional overlays and other images which makes using static images a pain. Plus, I suspect that I am going to need to be able to scale the background as the browser window changes size.
I realize that I can create an image of the GROW text and simply place it on top of the background image, but I would rather see if this effect can be accomplished “for real.”
This needs to work in IE8, 9, and FF 4. I can fallback to another effect for older browsers.
Any suggestions?
That affect can be achieved using CSS 3 image masking. However, at the moment, only webkit supports the property. I would implement something like this, then use a fallback for other browsers until everybody catches up to speed.
As a side note:You can also increase the CSS adoption be using ChromeFrame, or something similar
An Example from that link:
SVG images can be used as masks. For example, a partially transparent
circle can be applied as a mask like so:
<img src="kate.png" style="-webkit-mask-image: url(circle.svg)">
I ended up using two images without any holes or transparency. It's a hack but works in all browsers.
html5 or something like a gpd as php gui. But html5 doesnt work with ie8 or before, at least if the client doesnt have the chrome frame of google inc.
If you can play with mix-blend-mode property, there is simple solution that work on all modern browsers.
http://codepen.io/sajijohn/pen/OXEgkj
HTML
<h1>SUPER-FLY</h1>
CSS
#import url(https://fonts.googleapis.com/css?family=Raleway:900);
*{
margin: 0 0 0 0;
padding: 0 0 0 0;
}
html, body {
height: 100%;
width: 100%;
}
body {
background: url(http://unsplash.it/3200/1600?image=973) no-repeat no-repeat center center;
background-size: cover;
}
h1 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-family: raleway, sans-serif;
font-size: 80px;
line-height: 60px;
text-align: center;
padding: 20px;
/*/////////MAGIC//HERE////////*/
background: #fff;
color: #000;
mix-blend-mode: color-dodge;
/*////////////////////////////*/
}
https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode
I've got some button rollovers that work fine in browsers other than IE. I'm not using JQuery and this isn't IE6 -- I haven't tested it in IE6 yet. It's in IE8.
You can see what's happening here (look at it in IE vs. Firefox):
http://www.brighttext.com/socialtech/index.html
I'm using the technique of showing one or another button in response to a rollover by changing the background-position. I've tried various solutions proposed for IE6 issues but nothing has worked. Can anyone see what's going on here? And why can we see the Home button in IE, but not the others?
Code:
<ul>
<li id="homeLink" class="ord">Home</li>
<li id="faqLink" class="current">FAQ</li>
<li id="speakersLink" class="ord">Speaker Info</li>
<li id="sponsorsLink" class="ord">Sponsor Info</li>
</ul>
css for the first two buttons (I did this for all four) inside the div, which is called mastheadLeft:
#mastheadLeft li#homeLink a {
height: 32px;
width: 86px;
display: block;
text-indent: -1000em;
background: url(../images/home_dual.jpg) no-repeat left top ;
border: none;
}
#mastheadLeft li#homeLink.current a {
background-position: left top;
}
#mastheadLeft li#homeLink.current a:hover {
background-position: left top;
}
#mastheadLeft li#homeLink.ord a {
background-position: left bottom;
}
#mastheadLeft li#homeLink.ord a:hover {
background-position: left top;
}
#mastheadLeft li#faqLink a {
height: 34px;
width: 75px;
display: block;
text-indent: -1000em;
background: url(../images/faq_dual.jpg) no-repeat left bottom;
border: none;
}
#mastheadLeft li#faqLink.current a {
background-position: left top;
}
#mastheadLeft li#faqLink.current a:hover {
background-position: left top;
}
#mastheadLeft li#faqLink.ord a {
background-position: left bottom;
}
#mastheadLeft li#faqLink.ord a:hover {
background-position: left top;
}
i've tried a lot of stuff including recreating your project (copying and pasting your source and css from the site given). from my side using my own images, it works perfectly in both IE 8 and firefox 3.
however i tried
http://www.brighttext.com/socialtech/images/faq_dual.jpg
in both browsers. and it opens the image in firefox but opens an unavailable image in IE 8. so maybe you should have a look at where your images are stored. like i said, with my test images, it seems to work perfectly.
however i tried
http://www.brighttext.com/socialtech/images/faq%5Fdual.jpg
in both browsers. and it opens the
image in firefox but opens an
unavailable image in IE 8.
I also had a problem with a jpg that did not open in IE but opened in other browsers it was due to the image being in CMYK rather then RGB.
Reference:
http://www.computerhope.com/issues/ch001283.htm
Well i think there are many reasons which cause this problem. I was having same problem and could not understand how to solve the issue then i realize i did not put a space between ")" and "left"
background:url(../images/sample.jpg)left top no-repeat
After adding a space between these two solved my issue in ie6,7 and 8.
Is there a reason some of the images are PNGs and some are JPGs? I'm curious if the missing-file issue has something to do with file type. Probably not, but I'm interested.
Also, when I do background images in anchor tags like this, the image has the no-hover half sitting on top of the hover half and do my CSS like this:
#mastheadLeft li a {
height: 34px;
display: block;
text-indent: -1000em;
border: none;
}
#mastheadLeft li a:hover, #mastheadLeft li.current a {
background-position:0 -34px;
}
#homeLink a {
width: 86px;
background: url(/images/home_dual.jpg) no-repeat;
}
#faqLink a {
width: 75px;
background: url(/images/faq_dual.jpg) no-repeat;
}
That makes the CSS a lot cleaner and sets the exact same rules for all elements except the ones that are unique which, in this case, is just the background image used and the width. That way if something's going wrong, it'll be wrong for all the images.
I also use exact pixels instead of depending on the generic "top," "left," etc. values in CSS. More exact control.
Perhaps not a final answer, but at least it'll clean up your CSS so it's easier to find the problem.