Change image on mouse over with CSS not working - html

Using CSS, I would like an image/link that changes as the mouse moves over it. I don't understand why the code below is not working. #user.twitter does have a value. Since the link has no text, only an image, I'm a bit uncertain what to place as the first value behing the brackets. As it stands, no image at all shows up on the screen. What is wrong with the code below?
Html code:
<%= link_to("", #user.twitter, :class => "twitter") %>
CSS:
.twitter {
width: 20px;
height: 20px;
background: image-url('twitter.png');
}
.twitter:hover {
background: image-url('twitter_.png');
}
Update: If I check the page's source code it is:
<a class="twitter" href="http://www.example.com"></a>

It's hard to be sure without a demo with the actual HTML & CSS but your CSS is slightly malformed.
Also, the link would need to be inline-block or block rather than the default display:inline
.twitter {
width: 20px;
height: 20px;
background-image: url(http://4.bp.blogspot.com/-HkpT3JSkNWA/Txcu2eo0A-I/AAAAAAAAAlY/0eUq2M85Px8/s000/twitter.png);
background-size: cover;
display: inline-block;
}
.twitter:hover {
background-image: url('http://www.easychirp.com/images/share/twitter.png');
}
<a class="twitter" href="http://www.example.com"></a>

.twitter {
width: 20px;
height: 20px;
background: url('twitter.png') no-repeat;
}
.twitter:hover {
background: url('twitter_.png') no-repeat;
}

Here's my CSS:
.twitter {
width: 20px;
height: 20px;
background-image: url('twitter.png');
}
.twitter:hover {
background-image: url('twitter-hover.png');
}

Related

CSS btn - background image doesn't appear

my problem seems to be quite simple. I want to create the button which is png and has hover via .png also. I need this for email campaigns becouse Outlook doesn't understand some css attributes.
I tried make it simple
.button {
border: none;
background: url(/image1.png);
}
.button:hover {
border: none;
background: url(/image2.png);
}
And everything is just white. Any help will be great :)
according to documentation, you should do it like that,
background: url("/image1.png");
.button {
width: 50px;
height: 50px;
border: none;
background: url("https://i.stack.imgur.com/teLso.jpg?s=48&g=1");
}
.button:hover {
border: none;
background: url("https://graph.facebook.com/160520007817300/picture?type=large");
}
<button class="button"></button>
You have an error, use the simple, or double quotes "" - '', an example:
button{
background: url('https://s-media-cache-ak0.pinimg.com/736x/24/fe/e1/24fee13b4dc475c435984ab0aa1b8ecb.jpg');
background-size: 500px 100px;
background-position: center;
width: 500px;
height: 40px;
}
<button> Example button </button>
Same with any of the other html elements.

Image Sprite Will Not Show

I can't seem to get the image sprite to display. Can someone look at the code and tell me if I have it correct? I have checked the code and can't seem to figure out what's wrong.
CSS
#nav-footer
{ background:url(./_img//Footersprite.png) repeat-y;
width: 490px;
height: 40px;
margin: 0;
padding: 0;
}
#nav-footer li, #nav-footer a {
height: 40px;
display: block;
}
#nav-footer li {
float: left;
list-style: none;
display: inline;
}
#whyroofrepair a:hover { background:url("/_img/Footersprite.png") 0px -40px no-repeat; }
#savings a:hover { background:url("/_img/Footersprite.png") -98px -40px no-repeat; }
#enviromental a:hover { background:url("/_img/Footersprite.png") -229px -40px no-repeat; }
#advantage a:hover { background:url("/_img/Footersprite.png") -352px -40px no-repeat; }
#whyroofrepair { width: 55px; }
#savings { width: 55px; }
#enviromental { width: 55px; }
#advantage { width: 55px; }
HTML
<ul id="nav-footer">
<li id="whyroofrepair">Why Repair</li>
<li id="savings">Savings</li>
<li id="environmental">Environmental Benefits</li>
<li id="advantage">Roof Rx Advantage</li>
Blockquote
http://jsfiddle.net/LQCm2/2/
I tested this using Js fiddle.
can some one take a look?
First, change ./_img//Footersprite.png to ../_img/Footersprite.png
If that doesn't solve the problem then proceed below:
If your _img folder, containing the sprite:
Live next to your css file, then your image path should be like
_img/foo.jpg
Live just outside your css file's parent folder, then your image
path should be like ../_img/foo.jpg
Live in the root of your project, then your image path should be
like /_img/foo.jpg
EmileKumfa - I added additional info. Please see original post

CSS Sprites - using just one piece of an image as a background for part of an element

I use the CSS Sprite Technique with a background image that looks something like this:
The CSS code for the icons:
div.icon {
background-color: transparent;
background-image: url("/images/icons.png");
background-position: 0 0;
background-repeat: no-repeat;
display: inline-block;
height: auto;
vertical-align: text-top;
width: auto;
}
div.icon:empty {
width:16px;
height:16px;
}
div.icon:not(:empty) {
padding-left:20px;
}
div.icon.attenuation {
background-position: 0 0;
}
My icons can be used like this:
<div class="icon warning"></div>
I want to put some text inside my icons like:
<div class="icon warning">There is a warning on this page</div>
But the problem is that the background image covers the entire text area:
The question is: how can I use only part of an image as a background image for part of my element?
Notes:
setting width to 16px for div.icon doesn't help.
Remember, where ever possible, you shouldn't change your markup just to achieve a design. It is possible using your markup.
div.icon:before {
content: "";
background-color: transparent;
background-image: url("/images/icons.png");
display: inline-block;
height: 16px;
vertical-align: text-top;
width: 16px;
}
div.icon:not(:empty):before {
margin-right: 4px;
}
div.icon.attenuation {
background-position: 0 0;
}
You have two ways:
1)Your markup must be like this:
<div class="icon warning"></div><div class="txt">There is a warning on this page</div>
.icon {width:10px(for ex.)}
2)You must change the image. Icons in the image must be below the another
Sorry, my previous answer was not well though out.
Edit:
If you have a 16px padding, you should set the width to 0, not 16px. And I've got troubles getting the :not(:empty) bit to work on all browsers; better get rid of it. So the CSS becomes:
.icon {
...
width:0; height:16px; padding-left:16px;
}
.icon:empty {
width:16px; padding-left:0;
}
jsFiddle
set width: 16px; height: 16px; overflow: hidden; text-indent: -9999em; and remove padding

HTML5 Input Validation images with CSS3

I am currently working on an HTML5 form and using CSS3 for the styling. I have added CSS for input:required and input:valid and input:invalid to make an image get shown inside the text box.
Both the required and invalid CSS work fine but for some reason input:valid gets ignored and is just replaced with the same image as input:required.
Below is the CSS that I have used
input:required.fields, textarea:required.fields, select:required.fields
{
background:url("images/asterix.png") no-repeat;
background-position: right;
width: 200px;
background-color: white;
}
input:focus:required:invalid.fields, textarea:focus:invalid.fields, select:focus:invalid.fields
{
background:url("images/error.png") no-repeat;
background-position: right;
width: 200px;
background-color: white;
opacity: 1.0;
}
Both CSS sections above work fine without any problems but its the CSS below that for some reason is not working.
input:valid.fields, textarea:required:valid.fields, select:value.fields
{
background:url("images/tick.png");
background-position: right;
width: 200px;
background-color: white;
opacity: 1.0;
}
In case it was to do with the image not being found I made the invalid image be the tick.png image and this worked fine but the valid section never seems to get called.
Thanks for any help you can provide.
I just used the following on my form:
input[required]:invalid {
background: #efdee0 url(../images/invalid.png) no-repeat center right;
}
input[required]:valid {
background: #f3f8ed url(../images/valid.png) no-repeat center right;
}
but then my fields are all required (http://www.paul-ellis.co.uk/contact.htm)

Add URL link in CSS Background Image?

I have a CSS entry that looks like this:
.header {
background-image: url("./images/embouchure.jpg");
background-repeat: no-repeat;
height:160px;
padding-left:280px;
padding-top:50px;
width:470px;
color: #eaeaea;
border-bottom:1px solid #eaeaea;
}
How can I add the link to the the background image in that CSS?
The full CSS can be found here and the html that uses is there.
Try wrapping the spans in an anchor tag and apply the background image to that.
HTML:
<div class="header">
<a href="/">
<span class="header-title">My gray sea design</span><br />
<span class="header-title-two">A beautiful design</span>
</a>
</div>
CSS:
.header {
border-bottom:1px solid #eaeaea;
}
.header a {
display: block;
background-image: url("./images/embouchure.jpg");
background-repeat: no-repeat;
height:160px;
padding-left:280px;
padding-top:50px;
width:470px;
color: #eaeaea;
}
Using only CSS it is not possible at all to add links :) It is not possible to link a background-image, nor a part of it, using HTML/CSS. However, it can be staged using this method:
<div class="wrapWithBackgroundImage">
</div>
.wrapWithBackgroundImage {
background-image: url(...);
}
.invisibleLink {
display: block;
left: 55px; top: 55px;
position: absolute;
height: 55px width: 55px;
}
You can not add links from CSS, you will have to do so from the HTML code explicitly. For example, something like this:
<li id="header"></li>