【发布时间】:2018-08-13 15:43:15
【问题描述】:
我们的网站上有一个搜索栏,在 iPhone 上查看时不会延伸到整个页面。如果我们在 Chrome 或 IE 上进行 Inspect 并缩小屏幕宽度或在 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')">
<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 不同的问题?
谢谢
【问题讨论】:
-
您的头部是否包含移动视口元标记?例如:
<meta name="viewport" content="width=device-width, initial-scale=1"> -
叮,叮,叮,叮!哇,它有效!太感谢了。我已经为此工作了好几天。我不知道这个用于移动设备的元标记。
-
@doppler 将评论变成答案,并提供更多解释,以便将问题标记为已回答