首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在移动环境下改变图像位置

问在移动环境下改变图像位置
EN

Stack Overflow用户
提问于 2016-01-31 18:25:41
回答 2查看 6K关注 0票数 2

在手机上,我想把我的图像切换到文本块的顶部。当前代码如下所示,但它正在失败。

代码语言:javascript
复制
    <div class="col-md-10 col-sm-12 col-xs-12 center-block">
        <div class="banner-text col-xs-12 col-xs-push-12">
            <h1>Access all your<br/>apps</h1>
            <a href="#" class="btn btn-warning btn-lg clear-fix">Get Started</a>
        </div>
        <img src="img/banner.png" class="banner-image col-xs-12 col-xs-pull-12" />

    </div>

下面是代码的JSFiddle。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-01-31 19:55:12

对于全宽度列,推/拉类不能达到这一结果(因为cols的加起来超过了12)。

为了达到您想要的结果,您可以使用CSS柔性箱。

1)使用移动第一方法,要在最小设备的顶部显示的列首先出现在HTML中

2)使用媒体查询更改断点x处列的顺序(我选择了768 at作为示例):

示例代码:

HTML:

代码语言:javascript
复制
<div class="container re-order">
      <div class="row">
          <div class="col-xs-12 first">
                <h1>On mobile devices this col comes first</h1>             
          </div>
          <div class="col-xs-12 second">
                <h1>On larger screens this gets pulled up</h1>            
          </div>              
      </div>
  </div>

CSS:

代码语言:javascript
复制
@media (min-width: 768px) {
  .re-order .row {
    display: flex;
    display: -ms-flex;
    flex-direction: column;
  }
  .re-order .row .first {
    order: 2;
  }
  .re-order .row .second {
    order: 1;
  }
}
票数 2
EN

Stack Overflow用户

发布于 2016-01-31 19:38:44

您可以使用@media screen and (max-width ...px),以及在CSS(display:table;)中使用伪表。然后,为了更改元素的顺序,为顶层表元素分配display: table-header-group,为底部元素分配display: table-footer-group。

无论如何,看看你自己;)

CSS和HTML:

​

代码语言:javascript
复制
#example {
  display: table; width: 100%;
  table-layout: fixed;
}
  #banner-text {
    line-height:180px;
    background-color: #ff0000;
    display: table-header-group;
  } /* Will be displayed at the top of the pseudo-table */
  #banner-image {
    line-height:180px;
    background-color: #00ff00;
    display: table-footer-group; 
  } /* Will be displayed at the bottom */
  
@media screen and (max-width: 700px){
  #banner-text {
    display: table-footer-group;
  } /* Will be displayed at the bottom */
  #banner-image {
    display: table-header-group; 
  } /* Will be displayed at the top */
}
代码语言:javascript
复制
<div id="example">
    <div id="banner-text"><h1>TEXTBANNER</h1></div>
    <div id="banner-image"><h1>IMAGEBANNER</h1></div>
</div>

​

希望能帮上忙!

干杯,

Ps.在全屏模式下尝试代码片段,然后尝试调整浏览器窗口的大小;)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35117580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档