Solved

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

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

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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…
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 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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now