Solved

Re-setting a css style when a mobile phone user switches from vertical to horizontal view

Posted on 2016-08-18
2
80 Views
Last Modified: 2016-08-19
I have a webpage with a background image that looks fine when I hold my phone horizontally. Here's the code for the background image:
body {background:url(images/CoupleInSilhouette.jpg) no-repeat;
background-attachment:fixed; 
background-position:center; margin: 0 auto;
background-size: cover
}

Open in new window

But since the background-position is set to center, when I view the page holding the phone vertically, the left part of the image is hidden from view. Is there code that will move the position of the background to the right by a specified number of pixels? here's the page in question: www.dijitalrealm.com/JCMusic/ManOfMyWords.html

Thanks,
John
0
Comment
Question by:gabrielPennyback
2 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 500 total points
ID: 41761913
background-position can be expressed as a key word or a measurement or a combination of the two. It is usually expressed in pairs, the first keyword or measurement is the horizontal position and the second is the vertical position. The following would position the background 50 pixels from the left and centered vertically.
body{
	background-position: 50px center;
}

Open in new window

This style can be selectively activated according to orientation using media queries.
@media screen and (orientation: portrait) {
	body{
		background-position: 50px center;
	}
}

Open in new window

0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 41763188
Thanks, Kim, that works great. :- )
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
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)

860 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