Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Repeating Background Image using CSS.

Featured Replies

Hello everyone.

 

I'm currently designing a website that has a single background image defined within my css.

 

body {background:url(images/bg_image.jpg) no-repeat #040303;
}

 

This serves me well at certain resolutions. My problem is though, at higher resolutions, a black void will begin to appear to the right (See image attachment).

 

One technique that I've previously used is to create a 5 pixel wide repeating image based on the the background image, and it's worked perfectly, but the way I've written the CSS this time around doesn't seem to allow that?

 

Does anyone have any suggestions? I'd really appreciate any help towards this.

 

Thank you,

 

Chris.

post-11003-093333700 1284016156_thumb.jpg

Hmm cant quite work out whats going on with your picture, but if you want the background-image to repeat just remove the 'no-repeat' part, or state 'repeat' instead. Hope this helps.

  • Author

Thanks for getting back to me mrchristoph.

 

I understand what you're saying, but unfortunately that would result in the main background image being repeated and it can look quite unsightly at higher resolutions.

 

Just to reiterate this is purely needed to get rid of that black void to the right so rather than just repeating the whole background image, I take a slice of that image of about 5px, and repeat that on the x axis.

 

As I suggested above,

 

One technique that I've previously used is to create a 5 pixel wide repeating image based on the the background image, and it's worked perfectly, but the way I've written the CSS this time around doesn't seem to allow that?

 

Is anyone else familiar with this technique? Please let me know if I'm not being clear enough.

 

Thanks,

 

Chris.

Can you link us to your site so we can see the code? That makes things easier to decipher :)

you can have 2 background images.

have your larger background image onthe body tag:

 

body {background:url(images/bg_image.jpg) no-repeat #040303;

}

 

 

but you can also have a background image on the html tag that will sit behind your body tag. So you can have a repeated background image on the html tag and a larger bacground image on the body tag.

 

html {background:url(images/bg_image.jpg) repeat-x;

}

The simplest method is to use a graphics program such as GIMP and use the dropper tool to get the hex value of the colour right on the edge of the background, change the #040303 for the red colour and it should look ok.

 

Otherwise you will require 2 divs nested with the full width div having a sliced background of 5px repeated and the inner div as the size you want. Have you considered centering the page too?

 

I often use this structure:

 

<div id="headerbg">

<div id="header">

</div>

</div>

<div id="contentbg">... etc

 

css would be:

 

headerbg {width: 100%; overflow: hidden}

header {width: 960px; margin: 0 auto}

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.