Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<!DOCTYPE html>

<html>

<head>
    <title>Secret of Beauty</title>
    <link rel="stylesheet" type="text/css" href="css/main.css">

</head>

<body>

<header>
    <nav>
        <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">Products</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
                <li><a href="#">Location</a></li>
            </ul>
    </nav>

        <h1>Secret of Beauty</h1>

    </header>

    <div class="col">Cool</div>
    <div class="col">Cool</div>
    <div class="col">Cool</div>
</div>

<footer>&#169;Secret Of Beauty</div>


</body>
</html>



above*******************THIS IS MY HTML.INDEX*********************************************above

C#
body {
    background-image:url(C:\Users\Public\Pictures\Sample Pictures\header-preview.jpg)
}


above*****************************************this is my main.css*****************************above

I am attempting to make my image cover my background on my website when I switch the property to background-color:"( blah blah)" it changes the color but it does not work when I attempt to put my image in can anyone tell me whats wrong with my code?
Posted

You are missing the point: C:\Users\Public\whatever is not an URL! If you put protocol name, like file:// in front (background-image:url("file://C:\Users\Public\Pictures\Sample Pictures\header-preview.jpg");), it will be an URL, but not one for web. The URL of the background image has to be one visible from client side, thus sitting on one or an other web server out there. Your C drive is not visible from all cleints - I hope so for your sake. Some browsers are not requiring double quotes, but it is part of the standard.

So in general such an attribute would look like:
C#
body {
    background-image:url("/images/header-preview.jpg");
}

Please note that this is a relative URL but absolute to the web server root.
If the image is located at some place relative to the actual styles sheet file (not the document!), you can use regular relative path notation, like background-image:url("../images/header-preview.jpg");. Of course you can use whole URI-s also, like: background-image:url("http://some.server.com/images/header-preview.jpg");.

See: http://www.w3schools.com/cssref/pr_background-image.asp[^]
 
Share this answer
 
v2
Comments
Member 11495876 3-Mar-15 17:21pm    
You are the mannnnnn <3. no but seriously thanks for the help as you can tell I am still new to this and very new to this website but I am glad I joined a good website with people that know what they are doing, take care.
Sergey Alexandrovich Kryukov 3-Mar-15 19:14pm    
Absolutely. Good catch, a 5.
—SA
Afzaal Ahmad Zeeshan 3-Mar-15 19:18pm    
+5
well first of all you are missing a semicolon ; at the end of your background-image declaration, try changing that first
 
Share this answer
 
Comments
Member 11495876 3-Mar-15 16:57pm    
I just attempted that but it did not work either obviously saved and refreshed but thank you for responding.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900