我在使用jQuery mobile和CSS3媒体查询创建响应式网格时遇到了困难。我确实有响应,但它不会重新排列我想要的方式。这就是我所拥有的。
这是一个2行乘5列网格。 我试图把它变成10行的单列。我可以这样做,但我想按照我想要的方式获得订单。
所以看起来像这样
|A|B|C|D|E|
|A|B|C|D|E|
我试图让它在下面执行此操作(我想要它AABBCCDDEE,但我只能按照ABCDEABCDE顺序管理它...)
这是我的网格代码:
<div class="ui-grid-d my-breakpoint">
<div class="ui-block-a">
<input type="image" id="jog" src="images/jog.gif">
</div>
<div class="ui-block-b">
<input type="image" id="rewfwd" src="images/rewfwdOff.gif">
</div>
<div class="ui-block-c">
<input type="image" id="hand" src="images/handOff.gif">
</div>
<div class="ui-block-d">
<input type="image" id="auto" src="images/autoOff.gif">
</div>
<div class="ui-block-e">
<input type="image" id="off" src="images/offOff.gif">
</div>
<div class="ui-block-a">
<a href="#jogPopup" data-rel="popup" data-role="button" data-theme="a" data-icon="gear" data-position-to="header">Jog</a>
</div>
<div class="ui-block-b">
<a href="#rewfwdPopup" data-rel="popup" data-role="button" data-theme="a" data-icon="gear" data-position-to="header" data-transition="slideup">R F</a>
</div>
<div class="ui-block-c">
<a href="#handPopup" data-rel="popup" data-role="button" data-theme="a" data-icon="gear" data-position-to="header" data-transition="slideup">Hand</a>
</div>
<div class="ui-block-d">
<a href="#autoPopup" data-rel="popup" data-role="button" data-theme="a" data-icon="gear" data-position-to="header" data-transition="slideup">Auto</a>
</div>
<div class="ui-block-e">
<a href="#offPopup" data-rel="popup" data-role="button" data-theme="a" data-icon="gear" data-position-to="header" data-transition="slideup">Off</a>
</div>
</div>
我知道这不是正确的CSS让它工作,我尝试了一些不同的东西,但这里是标准的响应式CSS
@media all and (max-width: 300px) {
.my-breakpoint .ui-block-a,
.my-breakpoint .ui-block-b,
.my-breakpoint .ui-block-c,
.my-breakpoint .ui-block-d,
.my-breakpoint .ui-block-e {
width: 100%;
float:none;
}
}
有人对如何做到这一点有任何想法吗?
谢谢!
答案 0 :(得分:2)
为了重新排列这些div的流动位置,你要么必须将它们绝对定位在你想要它们的位置[用CSS],要么物理地将节点移动到你想要它们的位置[用JS]。
第三种解决方案,你可以将你的初始html / css重新排列成这样的东西:
<强> HTML 强>
<div class="ui-grid-d my-breakpoint">
<div class="ui-block-a">
<input type="image" id="jog" src="images/jog.gif">
<a href="#jogPopup" data-rel="popup" data-role="button" data-theme="a" data-icon="gear" data-position-to="header">Jog</a>
</div>
</div>
<强> CSS 强>
.my-breakpoint .ui-block-a a {
margin-top:25px;
}
基本上,这会为您的“非折叠”视图提供两个堆叠行的效果。然后,在您的媒体查询中,您可以将所有A
和INPUT
元素设置为display:block
,以使它们形成一个堆叠列(并且它们自然会以您想要的方式堆叠)。
我小提琴,这个想法多了一点:http://jsfiddle.net/BddhH/
答案 1 :(得分:-1)
移动网格的简单解决方案
只需扩展BOOTSTRAP网格 - 就像这样
@media (min-width: 768px) {
.container {
width: 766px;
padding-right: 2px;
padding-left: 2px;
margin-right: auto;
margin-left: auto;
}
.mob-xs-1, .mob-sm-1, .mob-xs-2, .mob-sm-2, .mob-xs-3, .mob-sm-3, .mob-xs-4, .mob-sm-4, .mob-xs-5, .mob-sm-5, .mob-xs-6, .mob-sm-6, .mob-xs-7, .mob-sm-7, .mob-xs-8, .mob-sm-8, .mob-xs-9, .mob-sm-9, .mob-xs-10, .mob-sm-10, .mob-xs-11, .mob-sm-11, .mob-xs-12, .mob-sm-12 {
position: relative;
min-height: 1px;
padding-right: 2px;
padding-left: 2px;
}
.container-fluid {
padding-right: 2px;
padding-left: 2px;
margin-right: auto;
margin-left: auto;
}
.row {
margin-right: -2px;
margin-left: -2px;
}
}
.mob-xs-1, .mob-xs-2, .mob-xs-3, .mob-xs-4, .mob-xs-5, .mob-xs-6, .mob-xs-7, .mob-xs-8, .mob-xs-9, .mob-xs-10, .mob-xs-11, .mob-xs-12 {
float: left;
}
.mob-xs-12 {
width: 100%;
}
.mob-xs-11 {
width: 91.66666667%;
}
.mob-xs-10 {
width: 83.33333333%;
}
.mob-xs-9 {
width: 75%;
}
.mob-xs-8 {
width: 66.66666667%;
}
.mob-xs-7 {
width: 58.33333333%;
}
.mob-xs-6 {
width: 50%;
}
.mob-xs-5 {
width: 41.66666667%;
}
.mob-xs-4 {
width: 33.33333333%;
}
.mob-xs-3 {
width: 25%;
}
.mob-xs-2 {
width: 16.66666667%;
}
.mob-xs-1 {
width: 8.33333333%;
}
.mob-xs-pull-12 {
right: 100%;
}
.mob-xs-pull-11 {
right: 91.66666667%;
}
.mob-xs-pull-10 {
right: 83.33333333%;
}
.mob-xs-pull-9 {
right: 75%;
}
.mob-xs-pull-8 {
right: 66.66666667%;
}
.mob-xs-pull-7 {
right: 58.33333333%;
}
.mob-xs-pull-6 {
right: 50%;
}
.mob-xs-pull-5 {
right: 41.66666667%;
}
.mob-xs-pull-4 {
right: 33.33333333%;
}
.mob-xs-pull-3 {
right: 25%;
}
.mob-xs-pull-2 {
right: 16.66666667%;
}
.mob-xs-pull-1 {
right: 8.33333333%;
}
.mob-xs-pull-0 {
right: auto;
}
.mob-xs-push-12 {
left: 100%;
}
.mob-xs-push-11 {
left: 91.66666667%;
}
.mob-xs-push-10 {
left: 83.33333333%;
}
.mob-xs-push-9 {
left: 75%;
}
.mob-xs-push-8 {
left: 66.66666667%;
}
.mob-xs-push-7 {
left: 58.33333333%;
}
.mob-xs-push-6 {
left: 50%;
}
.mob-xs-push-5 {
left: 41.66666667%;
}
.mob-xs-push-4 {
left: 33.33333333%;
}
.mob-xs-push-3 {
left: 25%;
}
.mob-xs-push-2 {
left: 16.66666667%;
}
.mob-xs-push-1 {
left: 8.33333333%;
}
.mob-xs-push-0 {
left: auto;
}
.mob-xs-offset-12 {
margin-left: 100%;
}
.mob-xs-offset-11 {
margin-left: 91.66666667%;
}
.mob-xs-offset-10 {
margin-left: 83.33333333%;
}
.mob-xs-offset-9 {
margin-left: 75%;
}
.mob-xs-offset-8 {
margin-left: 66.66666667%;
}
.mob-xs-offset-7 {
margin-left: 58.33333333%;
}
.mob-xs-offset-6 {
margin-left: 50%;
}
.mob-xs-offset-5 {
margin-left: 41.66666667%;
}
.mob-xs-offset-4 {
margin-left: 33.33333333%;
}
.mob-xs-offset-3 {
margin-left: 25%;
}
.mob-xs-offset-2 {
margin-left: 16.66666667%;
}
.mob-xs-offset-1 {
margin-left: 8.33333333%;
}
.mob-xs-offset-0 {
margin-left: 0;
}
@media (min-width: 768px) {
.mob-sm-1, .mob-sm-2, .mob-sm-3, .mob-sm-4, .mob-sm-5, .mob-sm-6, .mob-sm-7, .mob-sm-8, .mob-sm-9, .mob-sm-10, .mob-sm-11, .mob-sm-12 {
float: left;
}
.mob-sm-12 {
width: 100%;
}
.mob-sm-11 {
width: 91.66666667%;
}
.mob-sm-10 {
width: 83.33333333%;
}
.mob-sm-9 {
width: 75%;
}
.mob-sm-8 {
width: 66.66666667%;
}
.mob-sm-7 {
width: 58.33333333%;
}
.mob-sm-6 {
width: 50%;
}
.mob-sm-5 {
width: 41.66666667%;
}
.mob-sm-4 {
width: 33.33333333%;
}
.mob-sm-3 {
width: 25%;
}
.mob-sm-2 {
width: 16.66666667%;
}
.mob-sm-1 {
width: 8.33333333%;
}
.mob-sm-pull-12 {
right: 100%;
}
.mob-sm-pull-11 {
right: 91.66666667%;
}
.mob-sm-pull-10 {
right: 83.33333333%;
}
.mob-sm-pull-9 {
right: 75%;
}
.mob-sm-pull-8 {
right: 66.66666667%;
}
.mob-sm-pull-7 {
right: 58.33333333%;
}
.mob-sm-pull-6 {
right: 50%;
}
.mob-sm-pull-5 {
right: 41.66666667%;
}
.mob-sm-pull-4 {
right: 33.33333333%;
}
.mob-sm-pull-3 {
right: 25%;
}
.mob-sm-pull-2 {
right: 16.66666667%;
}
.mob-sm-pull-1 {
right: 8.33333333%;
}
.mob-sm-pull-0 {
right: auto;
}
.mob-sm-push-12 {
left: 100%;
}
.mob-sm-push-11 {
left: 91.66666667%;
}
.mob-sm-push-10 {
left: 83.33333333%;
}
.mob-sm-push-9 {
left: 75%;
}
.mob-sm-push-8 {
left: 66.66666667%;
}
.mob-sm-push-7 {
left: 58.33333333%;
}
.mob-sm-push-6 {
left: 50%;
}
.mob-sm-push-5 {
left: 41.66666667%;
}
.mob-sm-push-4 {
left: 33.33333333%;
}
.mob-sm-push-3 {
left: 25%;
}
.mob-sm-push-2 {
left: 16.66666667%;
}
.mob-sm-push-1 {
left: 8.33333333%;
}
.mob-sm-push-0 {
left: auto;
}
.mob-sm-offset-12 {
margin-left: 100%;
}
.mob-sm-offset-11 {
margin-left: 91.66666667%;
}
.mob-sm-offset-10 {
margin-left: 83.33333333%;
}
.mob-sm-offset-9 {
margin-left: 75%;
}
.mob-sm-offset-8 {
margin-left: 66.66666667%;
}
.mob-sm-offset-7 {
margin-left: 58.33333333%;
}
.mob-sm-offset-6 {
margin-left: 50%;
}
.mob-sm-offset-5 {
margin-left: 41.66666667%;
}
.mob-sm-offset-4 {
margin-left: 33.33333333%;
}
.mob-sm-offset-3 {
margin-left: 25%;
}
.mob-sm-offset-2 {
margin-left: 16.66666667%;
}
.mob-sm-offset-1 {
margin-left: 8.33333333%;
}
.mob-sm-offset-0 {
margin-left: 0;
}
}
@-ms-viewport {
width: device-width;
}
.visible-xs,
.visible-sm {
display: none !important;
}
.visible-xs-block,
.visible-xs-inline,
.visible-xs-inline-block,
.visible-sm-block,
.visible-sm-inline,
.visible-sm-inline-block {
display: none !important;
}
@media (max-width: 767px) {
.visible-xs {
display: block !important;
}
table.visible-xs {
display: table !important;
}
tr.visible-xs {
display: table-row !important;
}
th.visible-xs,
td.visible-xs {
display: table-cell !important;
}
}
@media (max-width: 767px) {
.visible-xs-block {
display: block !important;
}
}
@media (max-width: 767px) {
.visible-xs-inline {
display: inline !important;
}
}
@media (max-width: 767px) {
.visible-xs-inline-block {
display: inline-block !important;
}
}
@media (min-width: 768px) and (max-width: 991px) {
.visible-sm {
display: block !important;
}
table.visible-sm {
display: table !important;
}
tr.visible-sm {
display: table-row !important;
}
th.visible-sm,
td.visible-sm {
display: table-cell !important;
}
}
@media (min-width: 768px) and (max-width: 991px) {
.visible-sm-block {
display: block !important;
}
}
@media (min-width: 768px) and (max-width: 991px) {
.visible-sm-inline {
display: inline !important;
}
}
@media (min-width: 992px) and (max-width: 1199px) {
@media (max-width: 767px) {
.hidden-xs {
display: none !important;
}
}
@media (min-width: 768px) and (max-width: 991px) {
.hidden-sm {
display: none !important;
}
}
}