【发布时间】:2018-03-30 19:55:50
【问题描述】:
我对在我们网站上调整屏幕大小时发生的事情感到困惑。 我的任务是更改搜索栏的大小,以便在我们切换到移动大小的屏幕时它会填满大部分屏幕。当我达到一定范围的屏幕宽度时,GO 按钮会下降到搜索文本框下方。下面是屏幕截图,html和css。我不明白的另一件事是为什么会发生这种行为,因为我使用的是百分比宽度。我想我通过随着屏幕宽度的减小而减少文本的百分比来解决这个问题。但是当我在 Chrome 中检查屏幕时,问题就消失了!任何关于为什么百分比宽度不能正常工作的见解将不胜感激。谢谢。
.mobilesearch .searchrow {
width: 100%;
}
@media only screen and (max-width: 1180px) {
.headersearchbox {
/*width: 650px !important;*/
width: 94%!important;
display: inline!important;
}
.searchbutton {
/*width: 60px!important;*/
width: 3%!important;
display: inline;
margin-left: -5px;
margin-top: 1px;
}
}
@media only screen and (max-width: 1048px) {
.headersearchbox {
width: 87%!important;
}
.searchbutton {
width: 3%!important;
}
}
@media only screen and (max-width: 627px) {
.headersearchbox {
width: 86%!important;
}
.searchbutton {
width: 3%!important;
}
}
@media only screen and (max-width: 570px) {
.headersearchbox {
width: 85%!important;
}
.searchbutton {
width: 3%!important;
}
}
@media only screen and (max-width: 523px) {
.headersearchbox {
width: 84%!important;
}
.searchbutton {
width: 3%!important;
}
}
@media only screen and (max-width: 482px) {
.headersearchbox {
width: 83%!important;
}
.searchbutton {
width: 3%!important;
}
}
@media only screen and (max-width: 448px) {
.headersearchbox {
width: 82%!important;
}
.searchbutton {
width: 3%!important;
}
}
@media only screen and (max-width: 418px) {
.headersearchbox {
width: 81%!important;
}
.searchbutton {
width: 3%!important;
}
}
@media only screen and (max-width: 392px) {
.headersearchbox {
width: 80%!important;
}
.searchbutton {
width: 3%!important;
}
}
@media only screen and (max-width: 348px) {
.headersearchbox {
width: 79%!important;
}
.searchbutton {
width: 3%!important;
}
}
@media only screen and (max-width: 330px) {
.headersearchbox {
width: 78%!important;
}
.searchbutton {
width: 3%!important;
}
}
<!--Mobile-->
<asp:Panel ID="PanelSearchMobile" runat="server" DefaultButton="btnSearchMobile" CssClass="row collapse search">
<br />
<div class="small-12 columns hideforhighres searchrow">
<asp:TextBox
ID="KeywordFieldMobile"
runat="server"
BackColor="white"
BorderColor="black"
ForeColor="black"
maxlength="100"
CssClass="headersearchbox"
placeholder="Search Products">
</asp:TextBox>
<asp:LinkButton ID="btnSearchMobile" CssClass="searchbutton"
runat="server" > Go</asp:LinkButton>
</div>
<!--End of Mobile-->
【问题讨论】:
-
您可能应该在父元素上使用 vw (viewport-width) 和 vh (viewport-height) 而不是 % 以使其在调整大小时缩放?
-
或者更好!只是 body{height:100vh;width:100vw} 并希望一切正常并调整它,因为它没有
-
使用宽度:94vw;解决了我的问题!非常感谢。我仍在学习很多关于使页面适应移动设备和改变屏幕尺寸的知识。我能够将最大宽度调整减少到仅 4 个保存代码。
-
没问题!只要你能继续做事,尽可能远离框架!!!适应前端框架很耗时。我花了 48 小时将小型多页网站转换为使用 vue 的单页应用程序,但我并没有留下太多印象,所以我开始做出反应,又花了 48 小时……走神了.. 你应该尽可能地使用原版语言为任何人制作任何东西,当你设法制作出很棒的东西而无需从网上查找东西时,你就可以尝试新东西了。在此之前我不会推荐。玩得开心编码! :D