简体   繁体   中英

Background Image Not Showing in Chrome, Firefox

I am trying to load background image to a page using Dreamweaver. It shows in IE and Edge but not Chrome or Mozilla. I have tried moving the photo's location (file path) and tried in both straight HTML and CSS with the same result. I cannot find another way to write the code or think of one (being very new to this) so that it will show in all browsers. This is the CSS code:

background-image: url('file:///D:/website.com/httpdocs/pic/greenleaf.jpg')

set in the body brackets;

and html:

<body background="file:///D:/website.com/httpdocs/pic/Demo Page Song Thumbnails/Jpeg Thumbnails/greenleaf.jpg">

Everywhere I look I find examples with ellipsis points, like url(...website.com/greanleaf.jpg) and the dots totally confuse me. I think perhaps I need help with how file paths work.

This is due to the implementation of the body and html tags in Firefox and Chrome browsers. the body and HTML tags are only as big as the HTML content of them. where as Edge and IE the HTML and Body are auto sized to the size of the view port.

Add this to your CSS

body, html{
    min-height:100%;
    min-width:100%;
}

Ok , so if your code is correct and the image it's shown in IE and edge try to

refresh your browser but not normally with this command : Control + Shift + R

so that you're sure to be running the latest and greatest version of what that web

site's serving.

First, you'll need to be sure that the browser is correctly locating the image.

A good way to be sure is looking at Chrome's network tab. Hit F12 in Chrome to reveal Developer Tools. Click the Network tab and then refresh the browser. You will receive a list of resources that have/have not loaded. If your image is listed in red, then it failed to load. Your problem will be an incorrect path.

This is a good resource for understanding relative file paths. https://css-tricks.com/quick-reminder-about-file-paths/

However, if it did load successfully, the image isn't showing for another reason. Without seeing all of your code, I can only make a guess. Is the container that your image is in empty? Without content or a specified height, the background image won't show in some browsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM