在iPhone上查看时,Div不会拉伸到100%的宽度

时间:2018-08-13 15:43:15

标签: ios css iphone mobile

我们的网站上有一个搜索栏,当您在iPhone上查看时,搜索栏不会延伸到整个页面。如果我们在Chrome或IE上进行检查并缩小屏幕的宽度,或者在Chrome上选择iPhone仿真器,则搜索栏将整个屏幕水平填满。但是,当我们在iPhone上打开该网站时,屏幕右侧会出现空白区域。该网站是www.skywalker.com。 html太旧且混乱。我们一直在清理此代码,因此,如果您可能看到导致此问题的原因,请告诉我。

相关的html是需要延伸的元素所在的位置 class =“ hideforhighres searchrow”

<div class="hideforhighres mobilesearch" style="text-align: center">
    <a id="ctl00_Header1_lnkStoreName2" class="logo hideforhighres" href="/" style="display:inline-block;height:72px;width:147px;"><img src="Images/Themes/skywalkerheader-sm.png" alt="Skywalker AV Supply" style="border-width:0px;"></a>
    <br>
<link href="/BVModules/Themes/Foundation4 Responsive/styles/styles.css" rel="stylesheet" type="text/css">
<div id="ctl00_Header1_Search2_pnlSearchBox" class="row collapse search" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_Header1_Search2_btnSearch')">
    <!--Desktop-->
    <div class="hideforlowres" style="margin-left: 25px;">
        <input name="ctl00$Header1$Search2$KeywordField" type="text" maxlength="100" id="ctl00_Header1_Search2_KeywordField" placeholder="Search Products" style="color:Black;background-color:White;border-color:Black;height:32px;width:780px;">
        <div style="margin-top: -24px; margin-left: 778px;">
            <a id="ctl00_Header1_Search2_btnSearch" title="Search" class="searchbutton" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$Header1$Search2$btnSearch", "", true, "", "", false, true))'> Search</a>
        </div>
    </div>
</div>
<!--End of Desktop-->
<!--Mobile-->
<div id="PanelSearchMobile" class="row collapse search" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_Header1_Search2_btnSearchMobile')">
    &nbsp;<br>
    <div class="hideforhighres searchrow">
        <input name="ctl00$Header1$Search2$KeywordFieldMobile" type="text" maxlength="100" id="ctl00_Header1_Search2_KeywordFieldMobile" class="headersearchbox" placeholder="Search Products" style="color:Black;background-color:White;border-color:Black;">
        <a id="ctl00_Header1_Search2_btnSearchMobile" class="searchbutton" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$Header1$Search2$btnSearchMobile", "", true, "", "", false, true))'>Go</a>
    </div>
    <!--End of Mobile-->
</div>
</div>

在CSS中,我尝试了100%和100vw

/* Mobile Search width */
.mobilesearch .row.collapse.search .hideforhighres.searchrow {
    width: 100vw;
}

#PanelSearchMobile {
    max-width: 100%;
    margin-right: 0;
}

有人知道iPhone浏览器的行为不同于Android或台式机Chrome和IE的问题吗?

谢谢

1 个答案:

答案 0 :(得分:1)

您的移动浏览器可能需要其他信息才能正确缩放内容。尝试在文档的viewport部分中包含以下<head>元标记:

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