CSS background-position doesn't help to change where the image is - html

by default styles are that:
.landing-icon.self-service-badge:before {
background-image: url("/images/Evolution/site/self-service-badge.svg");
height: 76px;
width: 76px;
}
and image is centered. but when using internet explorer, background image is on the left side. i tried this:
.landing-icon.self-service-badge:before {
background-size: cover;
background-position: center;
background-image: url("/images/Evolution/site/self-service-badge.svg");
height: 76px;
width: 76px;
}
but this doesn't work for me, image is still on the left side, what can you advice?

Have u tried using auto-align, here is an exemple.
img {
display: block;
margin-left: auto;
margin-right: auto;
width: 40%;
}

Related

The images don't appear when using hover

I'm trying to get an image to change to another when i hover over the image, but nothing appears on screen and I'm baffled. The HTML and CSS are in the same file. everything is in a folder called 'walrus' and within that folder are the html/css coding and an image floder called 'images'.
Here's the code:
<style>
.b-george {
width: 130px;
height: 195px;
background: url("images/beatlegeorge.jpg") no-repeat;
margin: 50px;
}
.b-george:hover {
background: url("images/george.jpg") no-repeat;
}
</style>
<div class="b-george"></div>'
You need to provide background-size value for that element:
background-size: 130px 195px;
.b-george {
width: 130px;
height: 195px;
background: url("https://www.netclipart.com/pp/m/1-15005_animals-clipart-png-cartoon-animals-png-cute-animal.png") no-repeat;
margin: 50px;
background-size: 130px 195px;
}
.b-george:hover {
background: url("http://pluspng.com/img-png/animal-png-i-absolutely-love-tigers-and-have-two-of-my-own-on-my-tattoos-347.jpg") no-repeat;
background-size: 130px 195px;
}
<div class="b-george"></div>

CSS how to set a image without set width and height

my problem :
I have the class .logo working perfecly with this size: width: 316px; height: 300px;
the problem is this logo never will have this size always, the width and height should not be defined, so next logo can fits well.
I tried remove the width and height without no success, when I do this the logo does not appear.
it is something I can do in the css to make this work without set width and height?
https://jsfiddle.net/pLfgam3r/1/
.logo {
background-image: url('https://lh5.ggpht.com/tq3WqEUxtRyBn-d_0t3j6WKNHuJDrmLq-FE3GAYrsAMQFIaS7FIgRLfzzql2SvfvLqto=w300-rw');
background-repeat: no-repeat;
width: 316px;
height: 300px;
display: inline-block;
margin-top: 20px;
margin-left: 20px;
}
.logo2 {
background-image: url('https://i.ytimg.com/vi/SfBR9aGrk9k/maxresdefault.jpg');
background-repeat: no-repeat;
width: 316px;
height: 300px;
display: inline-block;
margin-top: 20px;
margin-left: 20px;
}
<div class="logo"></div>
<div class="logo2"></div>
Set background-size: contain;
https://jsfiddle.net/wuqvwpkL/1/
I found this post:
Why doesn't the background image show up without specific width and height?
So your css should look like this:
.logo2 {
background-image: url('https://i.ytimg.com/vi/SfBR9aGrk9k/maxresdefault.jpg');
no-repeat: true;
display: block;
position: relative;
width: 316px;
height: 300px;
padding-bottom: 20%;
background-size: 100%;
background-repeat: no-repeat
}
This is working for both logos that has different sizes.
https://jsfiddle.net/pLfgam3r/4/

How to remove white space between paralax backgrond-image and a next div?

I was practising in css paralax and got a problem: between background image and a next div there is a white gap, you can just change the width of a viewport and scroll down to see it.
So, my question is: Why it's happening and what I should do to remove it?
A screenshot and Link on JSFiddle or
css code:
.car {
position: relative;
width: 100%;
height: 600px;
background: url(http://i63.tinypic.com/14viwxk.png) no-repeat;
background-position: top left;
background-size: contain;
padding-top: 100px;
padding-bottom: 0;
overflow: hidden;
background-attachment: fixed;
}
.car h1 {
line-height: 1.2;
}
.car figure {
width: 40%;
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 10%;
color: white;
}
figure p {
margin-bottom: 20px;
}
Your image is simply too small. Change background-size to cover and see what you get
What have say #Hunter it's correct, or you can change the height: 600px; to height: 300px; or use other pictures with height: 600px

When having image in div change on hover, the image is cut off

I'm trying to make an image change when a user hovers over it, but the method I used seems to cut off the image, not showing all of it. How can I have it scale the image to the size I specify, rather than just making the div that size and cutting off the rest?
HTML:
<div class="navbar-image" id="navbar-image-ID2Games">
</div>
CSS:
#navbar-image-ID2Games {
width: 5rem;
height: 5rem;
background-repeat: no-repeat;
background: url(http://i.imgur.com/Ou5cX4D.png);
}
#navbar-image-ID2Games:hover {
width: 5rem;
height: 5rem;
background: url(http://i.imgur.com/Tx0SVZr.png) no-repeat;
}
See here: https://jsfiddle.net/7a7ghfw4/
As you can see from the imgur url, the image is supposed to be a save icon, but it cuts off everything but the top left.
Add "background-size: contain" to both of your css rules.
#navbar-image-ID2Games {
width: 5rem;
height: 5rem;
background-repeat: no-repeat;
background: url(http://i.imgur.com/Ou5cX4D.png);
background-size: contain;
}
#navbar-image-ID2Games:hover {
width: 5rem;
height: 5rem;
background: url(http://i.imgur.com/Tx0SVZr.png) no-repeat;
background-size: contain;
}
This works:
#navbar-image-ID2Games {
width: 265px;
height: 265px;
background-repeat: no-repeat;
background: url(http://i.imgur.com/Ou5cX4D.png);
}
#navbar-image-ID2Games:hover {
width: 265px;
height: 265px;
background: url(http://i.imgur.com/Tx0SVZr.png) no-repeat;
}
I only changed the width and height for both classes

Responsive issue with background image in css

I have created a div with a class called "responsive_image" and inside that div i have a img tag. The code is,
<div class="responsive_image">
<img src="img1.png"/>
</div>
The css code is,
.responsive_image {
position: relative;
background: url(images/laptop.png) no-repeat center #f0f0f0;
width: 100%;
height: 190px;
text-align: center;
background-size: contain;
background-position: center;
}
.responsive_image img {
width: 240px;
height: 160px;
position: absolute;
top: 6%;
left: 16%;
max-width: 100%;
height: auto;
display: block;
}
Actually, the laptop.png image is the original laptop image with size of 310x186 and inside that, a image with the size of 240x160 and that should correctly fixed inside the laptop image.
From the above code, everything seems to be work perfectly but while going for responsive, each and every time i need to adjust the top and left section in the .responsive_image img. Is there any solution so that i no need to alter top and left?
You have to remove width:100% from the .responsive_image class. And give width:310px as per your laptop image size
Also you have used percentage with top and left position. Change it with pixel. As percentage have always dynamic behavior as per the screen size. USE percentage only when you built a main structure of the html.
.responsive_image {
position: relative;
background: url(images/laptop.png) no-repeat center #f0f0f0;
width: 310px;
height: 190px;
text-align: center;
background-size: contain;
background-position: center;
}
.responsive_image img {
width: 240px;
height: 160px;
position: absolute;
top: 20px;
left: 20px;
max-width: 100%;
height: auto;
display: block;
}