Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS Why Is Image background not working

Liam Ferguson

Active Coder
My image background just won't work no matter what I do!!! I have followed all the tutorials! Pls help me! here is the code that i have:
HTML:
<!DOCTYPE html>
<html>
<head>
    
    <title>HTML in sublime text 3</title>
    
    <style>   
body{
    background-color: black;
    text-align: center;
    color: white;
}
</style>

</head>
<body style= "background: url(https://cdn.cjr.org/wp-content/uploads/2019/07/AdobeStock_100000042-e1563305717660-1300x500.jpeg) background-size: 100% 100% background-repeat no-repeat background-position center">

    <span style='font-family: fantasy'><h1><center>How to code with HTML in sublime text 3</center></h1></span>
    <span style='font-family: arial'><h2><center>By liam Ferguson</center></h2></span>

</body>
<p><center>_________________________________________________________________________________</center>
    
</p>
<p>
    <span style='font-family: cursive'><P><center>Sublime Text 3 is a coding program that allows you to edit programs,create programs and edit text</center></P>
</p>

</html>
 
I modified your code so the body tag doesn't have the style param. I moved all that to the style tag:
HTML:
<!DOCTYPE html>
<html>
<head>
    
    <title>HTML in sublime text 3</title>
    
    <style>   
body{
    background: url(https://cdn.cjr.org/wp-content/uploads/2019/07/AdobeStock_100000042-e1563305717660-1300x500.jpeg);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;
    background-color: black;
    text-align: center;
    color: white;
}
</style>

</head>
<body>

    <span style='font-family: fantasy'><h1><center>How to code with HTML in sublime text 3</center></h1></span>
    <span style='font-family: arial'><h2><center>By liam Ferguson</center></h2></span>

</body>
<p><center>_________________________________________________________________________________</center>
    
</p>
<p>
    <span style='font-family: cursive'><P><center>Sublime Text 3 is a coding program that allows you to edit programs,create programs and edit text</center></P>
</p>

</html>

Not sure if you'd need semicolon separators in the style body parameter to make it work the way you had it.
 
This also works:

HTML:
<body style= "background: url(https://cdn.cjr.org/wp-content/uploads/2019/07/AdobeStock_100000042-e1563305717660-1300x500.jpeg); background-size: 100% 100%; background-repeat: no-repeat; background-position: center;">

Semicolons and colons added.
 
Back
Top Bottom