Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 更改移动设备的网站设计或调整浏览器大小_Html_Css_Mobile_Responsive Design - Fatal编程技术网

Html 更改移动设备的网站设计或调整浏览器大小

Html 更改移动设备的网站设计或调整浏览器大小,html,css,mobile,responsive-design,Html,Css,Mobile,Responsive Design,对不起,如果之前有人问过这个问题,我肯定在某个地方一定有答案,但由于某些原因,我找不到它,可能是使用了错误的搜索查询 我知道您可以使用媒体查询来定位不同的设备,例如: @media only screen and (max-device-width: 480px) { div#wrapper { width: 400px; } } 但我想知道的是,如何改变我的网站设计的基础上,它是在设备上查看 示例 <div id="mobileNav">

对不起,如果之前有人问过这个问题,我肯定在某个地方一定有答案,但由于某些原因,我找不到它,可能是使用了错误的搜索查询

我知道您可以使用媒体查询来定位不同的设备,例如:

@media only screen and (max-device-width: 480px) {
    div#wrapper {
        width: 400px;
    }
}
但我想知道的是,如何改变我的网站设计的基础上,它是在设备上查看

示例

<div id="mobileNav">
    <div id="namePic">
        <!-- Mobile user -->
    </div>
</div>
假设我的正常网站结构如下:

如果是桌面

<div id="user">
    <div id="profilePic">
        <img src="images/responSiveTest/ppic.PNG" class="p-img" />
    </div>
    <div id="uname">
        <h4 style="color:white">Welcome  Guest</h4>
        <p style="color:white">Please Log in</p>
    </div>
</div>

希望我所问的有意义,感谢这个令人惊叹的网站上的每个人的帮助,如果你想用纯JavaScript实现这一点,请看这里-

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code.. 
}
同样,您可以使用jquery来实现这一点-

$.browser.device = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));

如果您想用PHP实现这一点,可以使用

要检测手机或平板电脑等移动设备,可以使用此代码

require_once '../Mobile_Detect.php';
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');

我通常在我的项目中这样做。默认情况下,我准备内容,但其设置为display:none,当媒体查询检测到移动设备宽度时,它将为设备呈现适当的内容

使用CSS媒体查询

HTML

<div id="content">
    <div class="desktop">
        <!--
            some content and markups here. by default this is loaded in desktop
        -->
    </div>

    <div class="mobile_device_380px">
        <!-- content and some markups for mobile -->
    </div>

    <div class="mobile_device_480px">
        <!-- content and some markups for mobile -->
    </div>
</div>


请注意,您的页面可能需要很长时间才能加载。只需要限制你需要改变的东西,就要具体。

我知道这是旧的,但对于其他人来说,请考虑:只需隐藏非关键的“视觉”部分就可以使所有的东西都适合。更改标记通常意味着更改功能,这对最终用户来说不是一个好的体验。我已经有太多次接触到由于基本操作与桌面版本不匹配而无法使用的网站的“移动”版本。
  /* if desktop */
    .mobile_device_380px {
        display: none;
    }
    .mobile_device_480px {
        display: none;
    }


    /* if mobile device max width 380px */
    @media only screen and (max-device-width: 380px) {
        .mobile_device_380px{display: block;}       
        .desktop {display: none;}
    } 

    /* if mobile device max width 480px */
    @media only screen and (max-device-width: 480px) {
       .mobile_device_480px{display: block;}
       .desktop {display: none;}
    }