【发布时间】:2017-05-24 13:53:12
【问题描述】:
我有一个 jQuery Mobile 网页,目前有一个 width=device-width,但我的表单元素(文本字段和提交按钮)在台式计算机上查看时会拉伸到浏览器的宽度。
有没有办法设置最大宽度,以便这些元素(或整个内容 div)在移动设备上正确显示,但在台式计算机上查看时不会超过固定的最大宽度?
【问题讨论】:
标签: jquery jquery-mobile width
我有一个 jQuery Mobile 网页,目前有一个 width=device-width,但我的表单元素(文本字段和提交按钮)在台式计算机上查看时会拉伸到浏览器的宽度。
有没有办法设置最大宽度,以便这些元素(或整个内容 div)在移动设备上正确显示,但在台式计算机上查看时不会超过固定的最大宽度?
【问题讨论】:
标签: jquery jquery-mobile width
<style type='text/css'>
<!--
html { background-color: #333; }
@media only screen and (min-width: 600px){
.ui-page {
width: 600px !important;
margin: 0 auto !important;
position: relative !important;
border-right: 5px #666 outset !important;
border-left: 5px #666 outset !important;
}
}
-->
</style>
@media only screen and (min-width: 600px) 将 CSS 规则限制为最小窗口宽度为 600 像素的桌面设备。对于这些,jQuery Mobile 创建的页面容器的width 固定为600px,margin: 0 auto 居中页面。其余的在美学上改善了结果。
但是,有一个缺点:这并不能很好地与滑动动画配合使用。我建议禁用动画(可能还取决于使用@media 的媒体类型和屏幕尺寸),因为无论如何它在大屏幕上看起来都很奇怪。
【讨论】:
.ui-page 上使用max-width。并非所有浏览器都支持@media。
@media only screen and (min-width: 800px){
body {
background:transparent !important;
overflow:hidden !important;
}
html {
background: #fff;
background-attachment: fixed;
overflow:hidden !important;
}
.ui-page {
width: 340px !important;
border:60px solid #111 !important;
margin: 50px auto !important;
position: relative !important;
border-right: 20px #222 outset !important;
border-left: 20px #000 outset !important;
border-radius:25px;
-webkit-border-radius:25px;
-moz-border-radius:25px;
overflow-y:scroll !important;
min-height:600px !important;
height:600px !important;
max-height:600px !important;
padding-bottom:0px;
}
}
【讨论】:
.ui-page {
max-width: 320px !important;/*or 640 */
margin: 0 auto !important;
position: relative !important;
}
设计和测试 320 像素或 640 像素。 如果桌面为 640 像素(更大的分辨率),则其宽度为 640 像素,而在移动设备上则为移动设备的宽度。
如果需要,给边框
.ui-page {
border-right: 2px #000 outset !important;
border-left: 2px #000 outset !important;
}
【讨论】:
你可以使用document.getElementById("id").style.width="200px";
【讨论】: