background-image: url(“images/plaid.jpg”) no-repeat; wont show up

前端 未结 6 1139
青春惊慌失措
青春惊慌失措 2021-01-12 14:00

I can\'t seem to make my plaid.jpg the background on any of my pages, let alone all of them, I\'ve tried selecting it by body, html, *, the specific id of \"home\". nothing

相关标签:
6条回答
  • 2021-01-12 14:39
        <style>
        background: url(images/Untitled-2.fw.png);
    background-repeat:no-repeat;
    background-position:center;
    background-size: cover;
        </style>
    
    0 讨论(0)
  • 2021-01-12 14:42

    If that really is all that's in your CSS file, then yes, nothing will happen. You need a selector, even if it's as simple as body:

    body {
        background-image: url(...);
    }
    
    0 讨论(0)
  • 2021-01-12 14:42

    You may debug using two ways:

    1. Press CTRL+U to view page Source . Press CTRL+F to find "mystyles.css" in source . click on mystyles.css link and check if it is not showing "404 not found".

    2. You can INSPECT ELEMENT IN FIRBUG and set path to Image ,Set Image height and width because sometimes image doesnt show up.

    Hope this may works !!.

    0 讨论(0)
  • 2021-01-12 14:45

    Most important

    Keep in mind that relative URLs are resolved from the URL of your stylesheet.

    So it will work if folder images is inside the stylesheets folder.

    From you description you would need to change it to either

    url("../images/plaid.jpg")
    

    or

    url("/images/plaid.jpg") 
    

    Additional 1

    Also you cannot have no selector..

    CSS is applied through selectors..


    Additional 2

    You should use either the shorthand background to pass multiple values like this

    background: url("../images/plaid.jpg") no-repeat;
    

    or the verbose syntax of specifying each property on its own

    background-image: url("../images/plaid.jpg");
    background-repeat:no-repeat;
    
    0 讨论(0)
  • 2021-01-12 14:45

    Try this:

    body
    { 
        background:url("images/plaid.jpg") no-repeat fixed center;
    }
    

    jsfiddle example: http://jsfiddle.net/Q9Zfa/

    0 讨论(0)
  • 2021-01-12 14:52

    You either use :

    background-image: url("images/plaid.jpg");
    background-repeat: no-repeat;
    

    ... or

    background: transparent url("images/plaid.jpg") top left no-repeat;
    

    ... but definitively not

    background-image: url("images/plaid.jpg") no-repeat;
    

    EDIT : Demo at JSFIDDLE using absolute paths (in case you have troubles referring to your images with relative paths).

    0 讨论(0)
提交回复
热议问题