Issues getting CSS sprite made by me working - html

I made a CSS sprite using this online site. Here are the files I'm using. This is what I have right now in my HTML markup:
<img width="1" height="1" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="" title="" class="e-shop" />
Since src can't be null I set a empty GIF in base64. Now, the problem is that the sprite.png file isn't loaded. So I modified the original code changing to this:
.contactenos, .contactenos-1, img.e-shop, .e-shop-1, .faq, .faq-1, .fctjur, .fctjur-1, .fctnat, .fctnat-1, .vendidos, .vendidos-1{
background: url(sprites.png) no-repeat;
}
But it's not working, maybe I'm doing something wrong, it's the first time I did this, any advice or help?
Test 1
I made some changes to the original CSS as follow:
.contactenos, .e-shop, .faq, .fctjur, .fctnat, .vendidos {
background: url(sprites.png) no-repeat;
}
.e-shop{
background-position: -198px -2px ;
width: 128px;
height: 50px;
}
.e-shop:hover {
background-position: -200px -56px ;
width: 128px;
height: 50px;
}
But still not working, is the problem the tiny default src image?

If that's your entire CSS, then you're missing a few things. Here's a fiddle using your markup and CSS (with a hard coded background image):
http://jsfiddle.net/5jvdmzgc/
You'll need to specify your elements width and height (right now, they're 1x1) and also the offset of the background image (if any).
Updated CSS:
width: 150px;
height: 50px;
background-position: -70px -120px;
Updated fiddle with different sizes specified:
http://jsfiddle.net/5jvdmzgc/1/
You can use the CSS you wrote as a "base" (specifies the image source), and then extend that with individual classes (width/height/bg offsets).
Hopefully this helps!

Your gif is only 1px by 1px. So your bg image is not going to be visible. You'll need to either set the dimensions in your css or provide a gif with the correct dimensions.
For example if your background image/sprite was 50px by 50px you could do this:
img.e-shop {
width: 50px;
height: 50px;
}
or
<img class="e-shop" src="
R0lGODlhMgAyAIAAAP///wAAACH5BAEAAAAALAAAAAAyADIAAAIzhI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTNf2jef6zvf+DwwKh8Si8YhMKicFADs=
" />
Fiddle

Related

How to add a "background-image" to an "img" tag and switch display on mouseover?

I have an img tag like this (and I can't use a container)
<img src="https://example.com/first-image.jpg" class="my-image">
And I would like to display a second image instead of the first one on mouseover using only CSS. Maybe doing something like this:
.my-image:hover {
background-image: url("https://example.com/second-image.jpg");
}
I'm not sure if it that's possible. Any ideas?
Solution 1: HTML can be edited
You can do it by not using the src attribute and set the default image in your CSS, then change it on hover like so:
.my-image {
width: 200px;
height: 200px;
background-image: url(https://....jpg);
background-size: cover;
background-position: center;
}
.my-image:hover {
background-image: url(https://....jpg);
}
See working example here: https://jsfiddle.net/86ujL1dv/
Note that modern browsers don't load images until they're needed, so there will be a slight delay on the first hover, as the user's browser will load the second picture.
Solution 2: HTML cannot be edited
It's a bit of a hack, but you can set the size of the img to zero, and use padding to make it look the same, then use the background-image property, like so:
.my-image {
width: 200px;
height: 200px;
}
.my-image:hover {
width: 0;
height: 0;
padding: 100px;
background-size: cover;
background-position: center;
background-image: url(https://images.pexels.com/photos/4017166/pexels-photo-4017166.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260);
}
See live example here: https://jsfiddle.net/1bo7L89w/

Can the same image in HTML have different sources depending on whether the mouse is on it?

So here's the problem - i need an image to slightly change when the cursor is hovering on it. However, simply writing something like this in CSS styles:
img {src="";} img:hover {src="";}
seems to do nothing. Is there a solution to this problem using only HTML and CSS?
Thank you for your time!
You can use background-image property and change the url on hover
img {
height: 200px;
width: 200px;
background-image: url("https://pixy.org/src/477/4774988.jpg");
background-size: 200px 200px;
;
}
img:hover {
background-image: url("https://pixy.org/src/19/193722.jpg");
}
<img />

Background image not showing with CSS

I've tried multiple different ways but none displayed the image as background.
CSS
.spec{
background: url('white_logo_red_font.jpg');
height: 100px;
width: 150px;
}
HTML
<div class="spec">
hi
</div>
The image is in the same folder so the url is correct. I've also tried background-image instead of background.
Edit: image location
index.js is where the code is.
That is probably caused by the wrong image path.
Try using link from the web, for example: background: url('https://via.placeholder.com/350x150') the image should be displayed - that means that your css syntax is fine.
Then fix your path, you probably have to add './', '/images/', '../images/' before "white_logo..." the image path have to be relative to the css file.
try,
CSS
.spec{
background: url('../white_logo_red_font.jpg');
height: 100px;
width: 150px;
}
HTML
<div class="spec">
hi
</div>
I have noticed that there is something wring with the background image url background: url('white_logo_red_font.jpg'); use correct url.
You can try my code.
.spec {
background: url(https://images.unsplash.com/photo-1578163246111-e02c555d00e1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80);
height: 100px;
width: 150px;
background-size: cover;
background-position: center;
}
<div class="spec">
hi
</div>

remove the thin line in header images in bootstrap

I have basic code with bootstrap and a svg sprit in a header / menu.. and there is a thin gray background line in the icons.
http://codepen.io/anon/pen/dpzKoQ?editors=1100
can you please help. I have tried setting
border-* etc to 0 - and I can fix. I set the colors / background - but some place I am missing something.
some place it is getting the below value from normalize.less
border-image-width: 1 ;
code: please see codepen.
.icon {
display: inline-block;
background-repeat: no-repeat;
background-image: url(https://cdn.rawgit.com/srisitar/test/master/sprite.svg);
}
.icon-facebook {
width: 96px;
height: 96px;
background-position: 0 0;
}
.icon-twitter {
width: 96px;
height: 96px;
background-position: -128px 0;
}
<
div id="home">
<a href=" ">
<img class="icon icon-twitter"></a>
</div>
how do remove the gray line.
thanks
It's because you are using an img tag with no src attribute. Chrome is essentially indicating the size of the container with nothing in it.
If you don't want to place an image between the anchor tags, then don't use an image tag. It's not necessary to place anything between the tags.
Demo here.
You can use div tag with background-image in css instead of using img tag.

background : url(); not working

Details : Using Atom File Editor with Mac OS X, Making a new site on localhost and after saving it I check changes on chrome browser. Right now i have come across a problem which causes the image to not show up on the website while i was trying to set background image of a section tag in CSS.
Problem : I am trying to use the stellar.js parallax plugin and for that i need to set the background property of the section tag to an image of my choice. The problem is that when i use "background : url(parallax1.png);" the image does not show up on the website and only a white blank space is shown.
HTML File :
<!-- Attempting Parallax Here -->
<section class="parallax1 pic1">
</section>
<!-- Ending Attempt Here -->
CSS File :
.pic1
{
background : url(parallax1.png);
}
.parallaxcontent
{
background-attachment: fixed;
background-repeat: no-repeat;
position: relative;
background-size : cover;
width: 100%;
height: auto;
}
Points You Should Know :
the image parallax1.png is in the same directory and i have checked the spelling, which is correct.
I have also tried using background-image: instead of background: .
If i use < img src="parallax.png" /> the image shows up perfectly
i have tried to encase parallax.png in '' as well as "".
Any help would be appreciated,
Thanks.
Generally, you should have some content within the section tag or you can set in .pic1 class
min-height:200px;
Try background : url("parallax1.png");
Read more here
CSS background Property
take a look
html
<section class="parallax1 pic1">
</section>
css
.pic1
{
background: blue url("https://static.xx.fbcdn.net/rsrc.php/v2/y6/r/QDLPxJ5bMSg.png");
width: 100px;
height: 32px;
border:1px solid #000;
}
.parallaxcontent
{
background-attachment: fixed;
background-repeat: no-repeat;
position: relative;
background-size : cover;
width: 100%;
height: auto;
}
working Fiddle