Solved

background attachment:fixed ignores min-width

Posted on 2014-10-02
7
114 Views
Last Modified: 2014-10-21
Hi

i have a background image on body tag nad is set to background-attachment:fixed.

However this causes the min-width property of body and html tags to be ignored and the background keeps moving left on smaller screens

See what i mean here - http://dev.openwaterdesign.com/cutting_edge_coaching/

Any ideas how to solve?

Thanks
0
Comment
Question by:coolispaul
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40357835
The background shifts because you positioned it center top so it keeps the center of the image in the center of the vieport, and that forces it to move.

Min-width is doing exactly what it is supposed to do when the viewport gets less than 960px it adds scrollbars.

Cd&
0
 

Author Comment

by:coolispaul
ID: 40357875
So why then is the background moving left if the width is 960px?

the background should be central to 960px but its not doing that

Thanks
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40357992
The image is 1366x918. Therefore its center is 683px from the edge and as the viewport narrows has to shift to compensate and keep 683 in the middle of the viewport.  Background images are not part of the content and they do not adjust to content position.

Cd&
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 54

Expert Comment

by:Julian Hansen
ID: 40358042
You could try changing
body {
  background: url("../img/banner-home.jpg") no-repeat scroll center top #000;
  font-family: "Roboto",sans-serif;
}

Open in new window

To
body {
  background: url("../img/banner-home.jpg") no-repeat scroll left top #000;
  font-family: "Roboto",sans-serif;
}

Open in new window

That will stop the background image from shifting - if that is what you want it to do?
0
 

Author Comment

by:coolispaul
ID: 40358045
well it does actually work like i want  when you remove "background-attachment:fixed". This is causing the problem,
I do however want the bg fixed...

Ta
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 40358188
You get the same effect by changing the center to left as shown in my previous post.
0
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 500 total points
ID: 40365225
Use the fixed attachment with in background attributes like:
background: url("../img/banner-home.jpg") no-repeat fixed center top #000;

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question