Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Button Css BootStrap 2 32
Group texting 7 46
Problem with a CSS in a page 2 25
Could you point a way to form a view's combo based on Codeigniter's results? 4 16
Let Bitmoji into your life. Now is the time to learn a new language of smartphone messaging with this brief introduction.
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.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

929 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

12 Experts available now in Live!

Get 1:1 Help Now