Skip to content

Instantly share code, notes, and snippets.

@johnpolacek
Created November 16, 2012 18:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnpolacek/4089898 to your computer and use it in GitHub Desktop.
Save johnpolacek/4089898 to your computer and use it in GitHub Desktop.
Responsive Viewport
<script language="javascript">
// set viewport to zoom to 1200px wide on viewports > 640px wide
var viewPortTag = document.createElement('meta');
viewPortTag.id = 'viewport';
viewPortTag.name = 'viewport';
if (screen.width > 640) {
viewPortTag.content = 'width=1200';
} else {
viewPortTag.content = 'width=device-width';
}
document.getElementsByTagName('head')[0].appendChild(viewPortTag);
</script>
@johnpolacek
Copy link
Author

Idea for having a fixed width site that scales to the viewport on mobile, then at a certain point goes fluid width single column. This would be for setting the viewport meta on page load. Say you have a big wide website that looks good on 1200 wide, the viewport setting zooms the website to fit nice on tablets. Then you do a media query to detect small screen and have css that turns your fixed width to a single column grid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment