Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-08-18
2
Medium Priority
?
116 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 2000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

This article discusses four methods for overlaying images in a container on a web page
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

885 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