Solved

background attachment:fixed ignores min-width

Posted on 2014-10-02
7
110 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 51

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 51

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now