Solved

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

Posted on 2016-08-18
2
73 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

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