I have this JPG image that I am trying to use in CSS as a background-image for a div container. All different images I have tried work, but this one just wont render in the viewport. If I go to inspect element, it shows the thumbnail when I hover over the elements URL.
I have tried everything including:
Putting it in an img tag and giving it a static height/width
Converting it to png and svg'
Compressing it
Scraping the metadata
Using it in a different HTML/CSS file
import image from "./image.jpg";
//using React.js
<img src={image} className="image"/>//<-- doesnt work in img as src
<div className="imageBg"></div> //<-- doesnt work in div as bg
.image {
height: 100px;
width: 100px;
}
.imageBg {
height: 100px;
width: 100px;
background-image: url("./image.jpg");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
Here's the culprit: (its just a 2000x2000 729KB .jpg mockup image edited in photoshop)
Is there something wrong with this image?
If you guys dont believe me, heres the bug in action: codesandbox.io/s/hardcore-kare-212iuy?file=/src/App.js
It works fine when I open that in an incognito window, but if I open it in a regular window…
… the file name in your live example (although not in the code you included in the question) ends in ad0.jpg which is a naming convention that triggers common ad-blocking algorithms.
Don't call it that.
Moral of the story: If an image isn't loading then look at the Network tab of your browser to find out what happens when the browser tries to load it.
There is a high chance of the Image getting Corrupted, try doing a small edit in any editing software (photoshop, or even system default apps) and save it again and try using it!
You can also simply take a screenshot of it and try using it in your code
If that doesn't work, you can use this link https://i.stack.imgur.com/LGYHM.jpg in your src as a string, this is the image uploaded to Stackoverflow's drive and test it for time being! if that works as a permanent solution create an account and Try Uploading it to a Cloud Assert Provider like Cloudinary and add it as a Link in the src
Related
I am trying to add background image using css but nothing is displaying in the browser
.right-flex{
margin-left: 5px;
background-color: #deeaee;
padding: 1em 0;
background-image: url("images/christmas-is-coming-christmas-wreath.gif");
}
<div class="right-flex">
<p>Display Image</p>
</div>
I've tried your code (using my own local gif file for testing), it works fine across Chrome, Edge, Firefox and IE.
Just taking a wild guess, is your image folder stored in a different directory? If the image folder is stored under a relative file path, you can try below code (in this case, image folder is one level above):
background-image: url("../images/christmas-is-coming-christmas-wreath.gif");
If you got your gif file from a website, pasting the image link from the website directly into background-image: url() also works.
I am currently building a website and ran into a issue with my code. I am trying to set an image as a background for my header. I have checked the path to my image, the spelling of everything, and have checked my syntax online. Everything seems to match, so I don't understand why my image is not popping up. Any help you guys can give would be amazing. Thank you. Below is my css code:
header {
text-align: center;
background-image: url("image/concert.jpg");
background-size: 700px;
height: 333px;
width: 500px;
}
In addition to what other people already commented on your question, it is worth noting that the filepath must be relative to the css file's location.
Say your entire project is in a folder named root, and css is located in root/css/styles.css but image is in root/image/concert.jpg, then, from your stylesheet, you should call the image like background-image: url("../image/concert.jpg");
Like #David Alsbright said, you should check the development tools console of your browser. It will help you determine if there's a problem with the file path.
My code works and display fine on live preview of Bracket but doesn't show when open directly with Chrome or Safari.
HTML
<div class="jumbotron">
<p>we develop <span>brands</span></p>
projects
</div>
CSS
.jumbotron {
display: block;
width: 100%;
height: 665px;
background: url("/img/Creative/bg-final.jpg") center no-repeat;
background-size: cover;
padding: 0;
margin: 0;
}
I simply want my background image shown when open with Safari or Chrome.
Thank you
Brackets live preview creates a local server that's resolving "/img/Creative..." to the root of your project folder. When you open your HTML file in a browser, it's looking for "/img/Creative" at the root of your harddrive instead.
If you need the page to be openable in a browser without a server, you need to use a relative path. So if your CSS file is in "stylesheets/style.css", for example, you'd use "../img/Creative" to reference your image.
"../" takes you up a level in your folder structure.
You are using the wrong code.
Try this - background-image: url("paper.gif");
I know you are using the shorthand code but try this.
Also always put the image in the same folder so you don't have to write the whole long address again & again.
I have lots of .svg images like foo23.svg. I also have corresponding foo23.png. I'd like to use the SVG in my HTML for web browsing, but I'd like to have it so that when you right-click (or control-click) on the image, you have the option to download the PNG. Can this be done?
Currently I like using <object data="foo23.svg"> to insert the image. Can the above be done still using <object>?
An extension of my question comes from also having foo23.pdf and foo23.eps. Can right-clicking lead to several download options?
This is untested but the way I would approach this is:
HTML:
<img src="foo23.png" />
CSS (courtesy of https://stackoverflow.com/a/21421125/5158636):
img {
background-image: url(foo23.svg);
background-repeat: no-repeat;
height: 0;
width: 0;
padding: 35px 120px; // adjust that depend on your image size
}
That way the image that gets displayed should be the .svg file (won't work in all browsers: http://caniuse.com/#feat=svg-css) but the file you get prompted to save should be the .png file.
I have a gallery in my website. The gallery contains 15 images, each one of them is approximately 500KB (total size is 7.5MB).
Because the gallery takes a while to load (25 seconds on my computer, tough it depends on the connection), I want the visitor to know the gallery is loading, hence the Ajax loading GIF.
I want the visitor to see the loading GIF as soon as he enters the gallery page, until the the gallery images have been downloaded and are ready to be viewed.
In order to achieve my goal, this is what I've done:
This is the beginning of the body of the gallery HTML page:
<body>
<img src="images/ajax-loader.gif" alt="" class="hiddenPic" />
<!-- loading Ajax loading GIF before all the other images -->
And this is the gallery CSS part:
#gallery {
background: url(images/ajax-loader.gif);
background-repeat:no-repeat;
background-attachment: fixed;
background-position: center;
So basically, the loading GIF should be downloaded as soon as a visitor enters the gallery page, because it is the first object inside the <body> that is going to be downloaded. However, it's not visible due to the hiddenPic class.
This method should help making the loading GIF ready and visible as the gallery background as soon as possible, until all the gallery images have been downloaded and the gallery is ready.
However, the loading GIF doesn't work properly on Google Chrome; it works perfect fine on Firefox & IE (spinning flawlessly) - but gets stuck (doesn't spin properly) on Chrome, from the moment it appears until the gallery is ready.
Update: I know I can implement a better gallery (like the ones suggested in the comments) which would require less resources from the user when entering the gallery page - but I don't understand how this can be the cause for the problem when the GIF loader works perfectly on Firefox & IE.
Why doesn't the Ajax loading GIF work properly on Chrome?
You just need to delete this declaration on line 602:
background-attachment: fixed;
I also had the same problem. The way I fixed it was to put the loading gif in it's own element (to keep markup clean, use a pseudo element).
Now, instead of using the background-attachment rule, you can use position: fixed. Here's the code you should use (assuming you'd like that loader gif to sit right in the middle of the screen):
#gallery:after {
content: "";
background: url(images/ajax-loader.gif);
position: fixed;
top: 50%;
left: 50%;
width: 50px; /*change to the width of your image*/
height: 50px; /*change to the height of your image*/
margin-left: -25px; /*Make this 1/2 the width of your image */
margin-top: -25px; /*Make this 1/2 the height of your image */
}
Hope this helps!
I'm a strong advocate of using dataURI with base64-encoded images in this and similar situations. What it does is effectively eliminates the need for a separate http request to retrieve the spinner gif, meaning the "loading" animation is immediately available to be rendered. This makes the value of the UX improvement so more valuable than a couple extra kilobytes in overhead - especially since the stylesheet would be only downloaded once and then cached by the client.
This fiddle has the animation embedded from ajaxload.info, having added literally less than 1KB to the final CSS.
Note that this kind of resource embedding is not supported at all on IE7 (but IE7 users have much bigger concerns to address :)
You may try this using jQuery BlockUI Plugin (v2)
Hope this helps.
Personally for loaders i've always done it this way , I do not remember where i read it .. But its always worked for me ..
$(function(){
$('#overlay')
.hide()
.ajaxStart(function() {
$(this).css("display","inline");
})
.ajaxStop(function() {
$(this).hide();
});
});
What it does , is it takes the div with an id of overlay and on any AJAX request that goes out , makes it visible and once the ajax request is complete , it hides it out.
Let me know if u need more code.
Cheers.
In the CSS for #gallery
background-position: center;
Should be
background-position: center center;
You should also try to use jQuery. See http://yulounge.alienworkers.com/photogallery/ for an example.