scaling html page with iframe for mobile - html

How can I scale web page to look nice on mobile devices?
On page I have iframe. Iframe contains html5/javascript game that uses fixed position divs. I want to scale that iframe as well.
Thank you very much.

EDIT:
I know I wrote this a LONG time ago, but here is the best solution for modern browsers: CSS Media Queries.
A little bit like the HTML option bellow, CSS Medial Queries are a native approach to responsively reflow any elements depending on the browser size.
I usually base myself on a standard 980px website, and adapt it from there using these media queries:
#media (min-width: 1920px) {
// Your CSS here
}
#media (min-width: 1280px) {
// Your CSS here
}
#media (min-width: 768px) {
// Your CSS here
}
#media (min-width: 0px) {
// Your CSS here
}
The order is important as the browser will cascade down from the highest min-width to the one it needs.
There are great examples from Chris Coyer from CSS-Tricks.com here:
http://css-tricks.com/css-media-queries/
ORIGINAL POST:
You could simply use conditional CSS to give it a specific look for every screen size. There are a few way you could do it: With Javascript or with HTML (which is faster).
HTML: This example would use a certain CSS (iPad_Portrait.css in this case) when the device has higher resolution than 481px but lower than 1024px. It works great with iOS devices, even with the iPhone 4 and 4S with super high resolution displays. But does not work at all with android's high resolution displays.
<link rel="stylesheet" media="only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" href="iPad_Portrait.css" type="text/css">
JavaScript: This example involves browser detection which is not always reliable, but I have had pretty good results with the following code:
<script type="text/javascript">
$(document).ready(function()
{
if((/iphone|ipod/i.test(navigator.userAgent.toLowerCase())))
{
// DYNAMICALLY CHANGED THE CSS FILE FOR THE IPHONE SPECIFIC CSS.
$('#your_css_link_id').attr('href', 'the_name_of_your_css_file.css');
}
else if ((/ipad/i.test(navigator.userAgent.toLowerCase())))
{
// DYNAMICALLY CHANGED THE CSS FILE FOR THE IPAD SPECIFIC CSS.
$('#your_css_link_id').attr('href', 'the_name_of_your_css_file.css');
}
else if ((/android/i.test(navigator.userAgent.toLowerCase())))
{
// DYNAMICALLY CHANGED THE CSS FILE FOR THE ANDROID SPECIFIC CSS.
$('#your_css_link_id').attr('href', 'the_name_of_your_css_file.css');
}
else if ((/blackberry/i.test(navigator.userAgent.toLowerCase())))
{
// DYNAMICALLY CHANGED THE CSS FILE FOR THE BLACKBERRY SPECIFIC CSS.
$('#your_css_link_id').attr('href', 'the_name_of_your_css_file.css');
}
else
// IF NO MOBILE BROWSER DETECTED, MOST LIKELY IS A COMPUTER, THEN IT DEFAULTS TO THIS FILE.
$('#your_css_link_id').attr('href', 'the_name_of_your_css_file.css');
});
}
<script>
If you put that code in your head, it will choose the appropriate css file for each of the device types.

Related

css with media queries does not work properly when screen size is small

I have created a responsive website using Swiper. I have used #media queries in my css to fit different screen size and orientation.
Initially, I have 1 main css, 1 landscape css and 1 vertical css. I imported two orientation css into main css. Only main css is in html file. The website works fine with all screen sizes. The css snippet regarding the media is as below:
#media screen and (orientation:landscape) and (min-width:700px) {
#media screen and (orientation:landscape) and (min-aspect-ratio:16/10) {
#media screen and (orientation:portrait)
Then I read about not using import for css so I cat all .css into one file. I also deleted the two #import lines. Then the website does not work properly. Specifically, all elements on small screens return to normal size. I checked the css structure: these elements lose their style enclosed in #media {} thus inherent from their parent css.
The fiddle with all the code is here. It's not working because it supposes to grab local image files.
The working website with separate css files is this. It's on Github so you can see the source files easily.
I am really new to css so this might be due a stupid mistake..
Use these media screen for tablet and mobile if you are not importing hopefully it will help Thank's
beside your fiddle shows this on top }//]]> i dont know why might be js issue or some text in body
#media only screen and (max-width: 1024px){}
#media only screen and (max-width: 768px){}
#media only screen and (max-width: 767px){}

Using CSS Media Queries

I recently asked a question about resolution and how I can fix it in my ASP.NET web application.
With some of the answers I got I found that media queries was a good place to go.
I have set up my CSS document like the following:
#media only screen and (max-width: 640px) {
}
#media only screen and (min-width: 641px) and (max-width: 800px) {
}
#media only screen and (min-width: 801px) and (max-width: 1024px) {
}
#media only screen and (min-width: 1025px) {
}
I have been developing in 1600x800 and I am wondering how do I know what I need to change the sizes of the object to. Do I have to develop the application again in a smaller browser or is there an easier way to go.
HTML:
<link rel="stylesheet" type="text/css" href="Style/StyleSheet.css"/>
The approach is basically the same as when you are writing CSS without using media queries. You still have to deal with different window sizes.
Drag the window edge to make the browser smaller
Look at how the design holds up
Adjust the CSS
Refresh the page
You will need to change the sizes of your images and fonts and also change their positions based on the different screen sizes which you have set using the media queries. To check the different code you can resize your window and drag the border and see the effect if its working or not.
And also follow the steps which **#Quentin** has written it will help
this is not exactly the right approach to follow. you should start your website with a fluid css layout grid, google it a choose one that suits you. this is an example of a fluid grid: http://onepcssgrid.mattimling.com/.
When you set up everything and designed, stretch your browser and when the design "breaks", add a media query breakpoint. deciding your breakpoints before the development is not a good idea.
a good tool to test your design may be: http://bradfrostweb.com/demo/ish/?url=http%3A%2F%2Fwww.mediaqueri.es#random (enter your url in the top left box) but i usually prefer stretching my browser manually.
This is what I have done in my website and it is working fine:
<head>
<meta name="viewport" content="width=device-width">
<style>
#media screen and (max-width:1900px)
{
#content{
margin-left:251px;
margin-top: -197px;
}
}
#media screen and (min-width: 420px) and (max-width: 1000px) {
#sidebar {
margin-left: -30px;
}
#content{
margin-left:221px;
margin-top: -197px;
}
#separator
{
height: 50px;
}
}
</style>
</head>
I checked it by resizing my chrome window and then applied width accordingly. Hope it can help you.
CSS Media query are the best option to solve issue related to working with different size of browser and devices. you can check your application with different tools available that shows how your application look on different device and browser.
You can check by re-sizing your browser window or you can use browser extension to check your work
Google Chrome:
https://chrome.google.com/webstore/detail/responsive-web-design-tes/objclahbaimlfnbjdeobicmmlnbhamkg?hl=en
FireFox:
https://developer.mozilla.org/en/docs/Tools/Responsive_Design_View
Opera:
https://addons.opera.com/en/extensions/details/responsive-web-design-tester/?display=en
Safari:
http://www.midwinter-dg.com/downloads_safari-extension_responsive-resize.html
To learn more about css media queries visit: http://letsdopractice.com/css-media-queries/

Is there a way to hide a div in mobile view on a non-responsive site?

I'm looking for a way to hide a div when the user is using a mobile device, but does not have a responsive website. Thanks!
inyour css file
#media screen and (max-width: 800px){
#divid{
display: none;
}
}
you still have to see what is the max resolution where you want the div hidden
You could accomplish that with a bit of javascript
$(document).ready(function() {
if ($(window).width() < 640) {
$("#div").css("display", "none");
}
});
CSS or Javascript and what devices?
Using CSS you can
<link rel="stylesheet" type="text/css" href="mobile.css" media="handheld">
use a mobile.css on your site and hide a div in that CSS. But people downloading browsers to their devices starts to make determining if you are on a mobile device more complicated. I think firefox has a problem with that specific code.
A referance to media handheld is here http://www.w3.org/TR/CSS2/media.html
More media refs are available here http://reference.sitepoint.com/css/mediaqueries
An opensource mobile detection site is here http://detectmobilebrowsers.com/

Zoomin out of site (automatically in the html code)

I have a webpage (html + css file). When it's shown in its native zoom it doesn't look good. I need to zoom-out (twice click ctrl+-) to get it look good.
Hence, I want this zoomed-out format become the native zoom of the site, namely, that people seeing my site will see it that way by default (on Firefox, Chrome and Internet Explorer).
Question: Is there a way to do this? What is the simplest way to do this?
(I don't really code well html/css. I used a free template to build my own site.)
Its because your CSS is not changing according to the resolution
so use media queries
http://mediaqueri.es/
http://mobile.smashingmagazine.com/2010/07/19/how-to-use-css3-media-queries-to-create-a-mobile-version-of-your-website/
Use media queries to write different styles for different screen resolutions.
also, use ems and percentages for font-size widths, padding, margin etc.. so that when you zoom you page it gets changed relative to the parent as per resolution.
You can use #media query
#media (min-width: 700px) { ... }
#media (min-width: 700px) and (orientation: landscape) { ... }
#media tv and (min-width: 700px) and (orientation: landscape) { ... }
#media (min-width: 700px), handheld and (orientation: landscape) { ... }
Further more
You can also use window.resizeTo(iWidth, iHeight) method to resize your browser window.
This is a Trick that you can use in CSS, however remember that this will zoom out the HTML from the centre and mess up with the total alignment of you site.
However im sure if you play around a bit you may find this to your advantage.
CSS
html {
-moz-transform: scale(1.4);
-webkit-transform: scale(1.4);
transform: scale(1.4);
overflow-x:scroll;
overflow-y:scroll;
}
WORKING FIDDLE

CSS stylesheet for website app fullscreen and not fullscreen

I'm building a website, which will be used on an iPad. The problem is, that I need to have 2 stylesheets:
One for when the user will see in fullscreen mode (without the address bar) and one for when the site opens standard in Safari.
Is it possible to make a line like:
#media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {}
but when it is in fullscreen contra not?
In iOS 5 you should be able to target the size of the screen without the menu bar (which takes up exactly 18px), this way you'll know it's fullscreen, because it should be larger since the menu bar won't be there:
#media only screen and (min-device-width: 672px) and (max-device-width: 1024px) and (orientation:portrait) {}
I'm not 100% if that'll work, but I know the black bar at the top takes up 18px. And the dimensions would be as such:
landscape:1024x672
portrait: 768x928
Update
I've found out how we can do this with jQuery, it relies on window.navigator.standalone
$(document).ready(function(){
if (("standalone" in window.navigator) && !window.navigator.standalone) {
$('head').append("<link href='fullscreen.css' type='text/css' rel='stylesheet' />")
}
});
Now this assumes that mobile safari supports window.navigator.standalone and it should. Give it a try.
the media query you mentioned, works according to the screen width, that's the device screen dimensions (width), without taking into account whether its Safari or fullscreen(like u described w/o address bar). hope it makes sense.
I did a quick search, and found link. Hope it helps.