Skip to main content
Participant
Apr 28, 2020 2:44 PM UTC
Question

Multiple backgrounds (only want certain ones repeating)

Hello ,
Can anyone send a line or two to please help me with this? Using an older version of Dreamweaver, I have apage where I have a main background, and others throughout the page. I have tried the common "background-repeat: no-repeat" html code, CSS ideas, and other things, but nothing works.

It seems that the way in which the code is written, when the main background image is set to repeat, makes all the others repeat. Is the problem there then - should I change that code in the beginning part of the body code?

Thank you kindly in advance. Hope everyone is safe and healthy!

    This topic is closed to new replies. Start a new post to keep the conversation going.

    5 replies

    Nancy OShea
    Community Expert
    Community Expert
    Apr 28, 2020 9:05 PM UTC

    Simple. Use the background repeat and no-repeat properties.  See screenshot and code below.

     

     

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Background Repeat / No-repeat</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    body {
    background:#fff url(https://placeimg.com/100/200/people) top center repeat;
    }
    div {
    width:45%;
    margin: 0 auto;
    padding:3%;
    color:#FFF;
    background:#333 url(https://placeimg.com/400/200/arch) center center no-repeat;
    }
    </style>
    </head>
    <body>
    <div>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quas ea non recusandae, facilis. Sunt debitis expedita minus sapiente animi omnis odio quod nostrum. Nisi ipsum, accusantium expedita alias. Assumenda, aliquam.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quas ea non recusandae, facilis. Sunt debitis expedita minus sapiente animi omnis odio quod nostrum. Nisi ipsum, accusantium expedita alias. Assumenda, aliquam.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quas ea non recusandae, facilis. Sunt debitis expedita minus sapiente animi omnis odio quod nostrum. Nisi ipsum, accusantium expedita alias. Assumenda, aliquam.</p>
    </div>
    </body>
    </html>
    

     

    Post back if you have any questions.

     

    Translate
    Nancy O'Shea— Product User & Community Expert
    scloud3Author
    Participant
    Apr 30, 2020 4:20 AM UTC

    Thank you kindly for your help! I figured it out my noticing where to place the mentioned "no repeat" code, after related the background jpg code:

    background="images/all images/background 3.jpg" style="background-repeat:no-repeat;">

    Cheers!

    Translate
    Nancy OShea
    Community Expert
    Community Expert
    Apr 30, 2020 6:10 PM UTC

    This is invalid code.

    background="images/all images/background 3.jpg"

     

    Validate your code often and fix reported errors.

    Window > Results > Validation.

     

    Or go directly to the W3C's online validation service.

    https://validator.w3.org/

     

    Translate
    Nancy O'Shea— Product User & Community Expert
    pziecina
    Legend
    Apr 28, 2020 3:00 PM UTC

    Not certain what you are trying to do?

     

    If it is having different background images for various sections, then you should attatch a background image to each section.

    e.g.

    article {

    backround-image: xyz.png;

    }

    p {

    background-image: xxy.png;

    }

     

    If it is multiple background images for the same section, (e.g the body) then you use multiple background-images, seperated by commas, and the other properties should also be comma seperated.

     

    See - 

    /Using_multiple_backgrounds 

    Translate
    scloud3Author
    Participant
    Apr 28, 2020 4:29 PM UTC
    Thank you for the response. Specifically, I have a main background (for the entire page), and others used within tables and layers. The main one and two others, I would like to have repeating, and the others non-repeating.
    Translate