Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8179015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:54:30+00:00 2026-06-06T23:54:30+00:00

The problem is: I have a huge background image and content with those characteristics:

  • 0

The problem is: I have a huge background image and content with those characteristics:

  • the content is centered with margin: auto; and it has a fixed width
  • the position of the content is in relation to the image (like it fits in the middle of the image)
  • this connection is only horizontally (vertical scrolling moves everything around as expected)

This works fine, actually, on desktop devices with position fixed on the background image.

But the problem is: When I resize the window until it’s smaller than the content, the content is fixed on the left side, but the background image is still centered, as expected. In this case the connection between both elements gets lost.

I have this JavaScript that does the trick, but this is of course some overhead I want to avoid as it isn’t smooth anytime due to the calculation:

$(window).resize(function(){
    container.css('left', (body.width() - img.width()) / 2);
});

I also tried things like that:

<div id="test" style="
    position: absolute;
    z-index: 0;
    top: 0;
    left: 0;
    width: 100%:
    height: 100%;
    background: transparent url(path) no-repeat fixed center top;
"></div>

But this results in the same issue described above.

Is there any elegant CSS solution for this problem?

Demo

Try it yourself

NOTE

The image size is fixed and known and it never gets scaled by the browser.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:54:31+00:00Added an answer on June 6, 2026 at 11:54 pm

    Is this working for you? http://jsfiddle.net/wPmrm/24/

    HTML

    <div class="background">
    <div class="content">
        CONTENT
        <br><br>
        This example works fine until you the viewport size gets smaller than this content. After that the image isn't sticky anymore.
        <br><br>
        And check out vertical scrolling.
    
        <div style="height:1500px;"></div>
        END
    </div>
    </div>
    

    CSS

    div.background {
        min-width: 740px;
        background: url('http://placehold.it/1600x1050') top center fixed no-repeat;
    }
    
    div.content {
        width: 700px;
        height: 2000px;
        margin: auto;
        padding: 50px 20px;
        background: none;
        opacity: 0.7;
        color: #333;
    }
    

    .background should be the wrapper for .content with a centered background and have a minimum-width of the .contents width+padding.

    Update from comments:

    http://jsfiddle.net/wPmrm/28/

    We’ll have to use a media-query, so when the width is at max 740px we change the background position. Oh and we set background-attachment to fixed again.

    CSS added

    @media screen and (max-width:740px) {
        div.background {
            background-position: -435px 0;
        }
    }
    

    I don’t see why it is -435px ((1600-740)/2 would be 430) but it seems to be the most accurate value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge problem with the REPLACE SQL function in Microsoft SQL Server
I have a huge problem with this method im trying to make. I have
Hello I have a problem wherein I have to read a huge csv file.
I have the following problem, from c++ I send huge string[] to java. huge
I am having a huge problem in all browsers. I have a site where
Greeting! I have the following problem. I have a table with huge number of
I have a huge problem concerning png images. My png is a black/white letter
Background: I have to upload images from users. Problem: The images need to be
I have an image.png with white background and some trasparceny over it. I tried
I'm using Visual c# express 2008. I have a huge text file that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.