5

I need to set the min width of content to 480px so that anyone viewing on a screen <= to that will have to scroll accross to view the content. The reason being for this is that it is impossible to make the layout work below this resolution.

Here's what I have

<meta name="viewport" content="width=device-width,  initial-scale=1, maximum-scale=1, minimum-scale=1">

I need something like this but obviously this doesn't work

<meta name="viewport" content="width=device-width,, min-width=480px,  initial-scale=1, maximum-scale=1, minimum-scale=1">
Jacob Windsor
  • 6,750
  • 6
  • 33
  • 49

5 Answers5

3

This is a solution to have the responsive version of a web only for tablet and desktop.

This this code we disable the mobile version dynamically. On mobile:

<!-- Meta Responsive -->
<meta id="myViewport" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script>
window.onload = function () {
    if(screen.width <= 767) {
        var mvp = document.getElementById('myViewport');
        mvp.setAttribute('content','width=767');
    }
}
</script>
<!-- End of Meta Responsive -->
jalopezsuarez
  • 414
  • 4
  • 13
2

It sounds like you are trying to set the min width of the content on the page, not the viewport itself.This article might help you out.

You are probably looking to do:

@media all and (max-width: 480px) {
    // styles assigned when width is smaller than 480px;

}

Something like this, in that block you can sent the styles for content on screens that have a width of 480px and lower.

Hope that is what you are looking for.

Rchristiani
  • 424
  • 3
  • 18
0

I tried a lot of codes and achieved some good results doing a sort of realoading the viewport... But, I think that the best way is to create a full-responsive web site (up to 320px ;)

Thats the best aproach:

<script>
//VIEWPORT

function mobileFriendly() {
    setTimeout(function () {
        if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
            var ww = ( document.documentElement.clientWidth < window.screen.width ) ? jQuery(window).width() : window.screen.width; //get proper width
            var mw = 725; 
            //alert ("width" + ww);
            var ratio = ww / mw; //calculate ratio
            //alert ("ratio: " + ratio);
                if( ratio < 1 ){ //smaller than minimum size
                    jQuery("meta[name='viewport']").attr('content', 'initial-scale=' + ratio + ', maximum-scale=' + ratio + ', minimum-scale=' + ratio + ', user-scalable=yes, width=' + mw);
                }else{ //regular size
                    jQuery("meta[name='viewport']").attr('content', 'initial-scale=1.0, maximum-scale=2, minimum-scale=1.0, user-scalable=yes, width=' + ww);
                }
            }
        }, 600);
    }
    jQuery( document ).ready( function(){
    mobileFriendly()
    });
    window.addEventListener("orientationchange", mobileFriendly, false);

</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<meta content="user-scalable=yes, maximum-scale=1.6, width=device-width, initial-scale=1, target-densitydpi=device-dpi" name="viewport">
gtamborero
  • 2,898
  • 27
  • 28
-2

Your second solution does in fact work -- what you might not have seen is that you have 2 commas after width=device-width, which is probably why you don't have it working. I've copied it and had no problems.

Sometimes fresh eyes does it all.

Edit : However, yes, in your case, a media query is exactly what you need.

davewoodhall
  • 998
  • 3
  • 18
  • 43
-4
<script>
        //viewport just for screens under/with 480px width other screen widths show the whole page resized
        if(screen.width <= 480) {
            document.getElementById("viewport").setAttribute("content", "width=device-width, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;");} 
        //for devices with more and less/equal than 480px width 
        window.onresize = changeViewport;
            function changeViewport(){
                if(screen.width <= 480) {
                    document.getElementById("viewport").setAttribute("content", "width=device-width, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;");} 
                if(screen.width > 480) {
                    document.getElementById("viewport").setAttribute("content", "");}           
                }
    </script>