Viewport for phones only - html

I am trying to make a responsive layout that has a phone view and a normal view only (ie. Tablets should load the page normally).
Everything is working correctly as far as the CSS goes however the viewport is screwing up the zoom on tablets when they're in portrait mode. (They're zoomed in to their pixel width)
Is there a way to get tablets to zoom out to the full page while still having the phones load scaled to their size?
Here's what I have... Changing the initial scale to .75 almost works but then the iPhone loads the normal site when in landscape, which I don't want.
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" media="only screen and (max-width: 568px)" href="css/mobile-styles.css" />

Don't mess with the viewport, it'll only cause headaches and accessibility issues. Instead, create the CSS you want for phones(small screens) and then include the styles for the "full" site (large screens) in a min-width:500px(or some other breakpoint) media query.
Example CSS:
/*this will fire for any size screen*/
nav{
width:100%;
}
/*this changes the above styles for any screen over 500px*/
#media (min-width:500px){
nav{
width:50%;
float:left;
}
}

Related

Banner is too small on mobile device

At some point I know I need to bite the bullet and do some serious reading on responsive and adaptive design, but I was hoping there was a really simple way to address this issue.
I have the following web page, shown here in my desktop browser.
And here is the same page on my cell phone.
Although it's probably hard to tell here, the banner is too small when viewed on my cell phone.
Ideally, I would like to have it so:
The width of the page content (and the corresponding width of my <footer> element, which has a top border) does not take up the entire width of the browser when it's full screen on the desktop, but does take up the entire width of my cell phone.
The banner would never be bigger than the pixel width of the image on my desktop, but would take up the entire width of my small cell phone.
Is there any simplified approach to this?
You can use media-queries to handle style changes based on the viewport. For instance, you can do something like:
JS Fiddle Example
/* Desktop Styles here*/
footer {
background: blue;
width: 500px;
}
.banner > img {
width: 300px;
}
/* When the screen is smaller than 560px, specify what properties you wan to change. */
#media only screen and (max-width: 560px) {
footer {
width: 100%;
}
.banner > img {
width: 100%;
}
}
Apart from media queries which you should seriously look into for serious responsiveness, you will also need to adjust the viewport meta tag in your header.
Add <meta name="viewport" content="width=device-width, initial-scale=1"> to your <head> tag to instruct the phone browser not to attempt to display the page as in a zoomed-out state.
So, for instance:
...
<head>
<link rel="stylesheet" type="text/css" href="Style.css">
<title>Hooray Banana</title>
<meta name="keywords" content="This page is a placeholder for future content.">
<meta name="description" content="sc web group">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
...
Then F12 and view in a phone emulation mode or check on your phone directly.

Make only mobile based website

I am less confused to make a website only for mobile and tablet not a desktop. I need to know only one thing.
Should I use <meta name="viewport" content="width=device-width, initial-scale=1"> and define #media only screen for specific device?
Yes, however your website still will be accesible from other devices.I can explain it for you:
Using tag:
<meta name="viewport" content="width=device-width, initial-scale=1">
It will adjust webpage width to match device width and set initial scale to 1 (no zooming). So for example, if you open this page using iPad, web browse will display page in 1024x768 (landscape) or 768x1024 (portrait).
initial-scale=1
This will force to display webpage with zoom set to 1.
Using media queries CSS3 you can set different CSS styles for different devices:
Styles for Tablets
#media screen and (min-width: 768px) and (max-width: 1024px) {
/* Styles for tablets */
}
Styles for Desktop
#media screen and (min-width: 1025px) and (max-width: 1280px) {
/* Styles for Desktops */
}

Meta viewport not scaling website on iPad

I have a (rather simple) website that I wish to automatically scale and adjust such that the main content area fits in the screen without horizontal scrolling on iPad. On Landscape mode it works fine, however on portrait mode it leaves out part of it on the side, and the user has to scroll horizontally.
It normally works fine for other websites I did, but for this one I can't understand what is stopping Safari from doing this.
I added the following line at the top of the HTML but it doesn't seem to have any effect (I tried various alternatives like adding the initial-scale=1.0 etc. too)
<meta name="viewport" content="width=device-width, maximum-scale=1.0" />
What could be the reason this is not working?
Clarification
I am not looking for a media query solution. I am just trying to understand why for some sites the iPad (and other touch devices) automatically scale down a website to fit on screen, while in this case something is causing it not to. I am just trying to identify the reason for it.
there is fixed width given for inner container
div#branding{
width: 1024px;
}
#content{
width: 1024px;
}
div#footer{
width: 1024px;
}
change all the 3 width to 100% for #media screen
more information on #media screens can be found here
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio: 2) {
div#branding {
width: 100%;
}
#content {
width: 100%;
}
div#footer {
height: 40px; /* remove height */
display: inline-block; /* change display:block to display: inline-block; */
}
}
and it will work
the right side footer content will come down as the left side content is more
screenshot
note : your footer will broke as fixed height is given you can remove it
for fixing your footer change css for footer
div#footer {
height: 40px; /* remove height */
display: inline-block; /* change display:block to display: inline-block; */
}
screenshot
I used width:100% and it solves my orientation layout situations, but there seems to be media queries that can help too:
#media screen and (orientation:portrait) {
/* Portrait styles */
}
/* Landscape */
#media screen and (orientation:landscape) {
/* Landscape styles */
}
Check this site out for more: http://www.1stwebdesigner.com/css/how-to-use-css3-orientation-media-queries/
Let us know if it works out.
Depending on rules you got in your CSS you will need to assign portrait mode such as landscape or portrait and add desired width also.
#media screen and (orientation:landscape) and (max-width:1024px){
some rules that will be applied to iPad in landscape mode
}
And big big difference is this, which will be applied on all 1024px screens
#media screen and (max-width: 1024px){
some css rules for "normal" screens on max-width: 1024px
}
EDIT:
So make sure that you put your "container" divs on 100% in various modes and adjust all other elements. the scrollbar you got is actually DOM element with fixed div or margins and paddings that affect width of whole page
I think the meta tag has a minimum scale besides the maximum:
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
What I don't know is if it will make any difference at this point.
It should work in theory, along with:
#media only screen and (min-width: 480px) {
/* landscape */
}
#media only screen and (max-width: 479px) {
/* portrait */
}
I finally figured out the problem. iPad (and most touch devices) actually scale the website automatically, without the need of the <meta name="viewport" ... > if the website is not explicitly designed to be responsive.
However, this scaling does not seem to work when the website is too wide. My content was 1024px wide, which for some reason was triggering the devices to turn off scaling.
I changed the content's width to 960px (I don't know the actual threshold, but my other site that scales well had this width) and the issue was immediately fixed.
Adding this answer in case someone is looking for a reason why scaling is not working on his site.
Obviously this is not related to having a responsive site, this is just when the website is simple and scaling is enough.
What I'm noticing is that Safari by default scales the web page automatically. However if the user manually applies some scaling - Safari stops its automatic scaling.
In my case this was the reason why it scaled some sites and others don't.

Site doesn't fill the screen on the iPad

I'm developing a site that is 600 pixels wide and using responsive queries to make it fit in different devices. I'm using the following code:
<meta name="viewport" content="width=device-width" />
#media only screen and (min-width: 320px) and (max-width: 480px) {
/* iPhone */
.container { width: 100%; max-width: 480px; }
...
}
#media only screen and (min-width: 768px) and (max-width: 1024px) {
/* iPad */
...
}
I have a problem with the iPad, though. This device viewport is 768 pixels wide, and therefore the site renders correctly but is shifted to the left because its width is narrower.
My question is, is there a way to center the site or alternatively make it fill the whole iPad screen?
Thanks in advance
Try this:
<meta name="viewport" content="600" />
More on that here: https://developer.mozilla.org/en/docs/Mozilla/Mobile/Viewport_meta_tag
Or to centre the container (assuming it's 600px wide)
.container {
width:600px;
margin:0 auto;
}
Though it may be worth making the site larger in the first place.
Why make the site 600px wide? You should make the site fill the 100% of the viewport by default, and then adjust the margins around the content, font-size, the size of the images etc. for each screen size so that the content adapts.
You could take this site as example. If you try making the browser window bigger and smaller you'll see that all the content adapts (and even a mobile menu appears when the viewport is that small) All of that is accomplished using media queries for different screen sizes.
(Sorry about my syntax)

how to fix my website layout to small and big screens

Hello guys i have made a website by the help of Dreamweaver in HTML, CSS and JavaScript now my screen is 15.4 inch whenever i m opening in small screens so it give me an scroll bar to see whole of my website in the width form.
i have used PX with divs that i created my whole website instead of percentage but i don't know why i m facing this problem.
.wrapper
{
width:1320px;
height:760px;
border:solid 1px #000;
margin:0 auto;
background:url(images/Background_Image.jpg) no-repeat;
}
.wrapper .logo
{
background:url(images/logo.png) no-repeat;
width:395px;
height:180px;
margin-left:323px;
margin-top:10px;
float:left;
// same method for other divs
}
Add this meta tag to your head
viewport - most important and most useful of all the meta tags. width controls the width of viewport of device, initial-scale loads the initial zoom level when page loads
<meta name="viewport" content="width=device-width, initial-scale=1">
Check Mozilla Docs - Viewport
make use of media queries
#media screen and (min-width: 700px) and (orientation: landscape) { ... }
Mozilla Docs - Media queries
Percentage/em is good if you want your site to be responsive