【问题标题】:Bootstrap align div horizontal to vertical on responsiveBootstrap在响应时将div水平对齐到垂直
【发布时间】:2019-04-17 01:53:11
【问题描述】:

HTML:

.wrap {
  display: flex;
  background: white;
  padding: 1rem 1rem 1rem 1rem;
  border-radius: 0.5rem;
  box-shadow: 7px 7px 30px -5px rgba(0,0,0,0.1);
  margin-bottom: 2rem;
}
.vcenter {
   margin: auto;
   margin-left: 10px;
}

.mbr-section-title3 {
  text-align: left;
}

.display-5 {
   font-family: 'Gotham-Book-Regular';
   font-size: 1.4rem;
}
.mbr-bold {
   font-weight: 700;
}

.display-6 {
   font-family: 'Gotham-Book-Regular';
   font-size: 1.4rem;
}

.fit100 {
  width: 100px;
  height: 100px;
}

.img-circle {
  border-radius: 50%;
} 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
    <div class="col-md-6">
        <div class="wrap">
            <div>
                <img src="https://www.drupal.org/files/issues/default-avatar.png" class="img-circle fit100" alt="" title="">
            </div>
            <div class="text-wrap vcenter">
                <p class="mbr-fonts-style text1 mbr-text display-6">On Bawabba, you will find various types of services all under one roof. You can compare different profiles and contact the one that best suits your requirement directly wdslfjlksjdfk sdjfkljfsdkf sdk.</p>
                <h2 class="mbr-fonts-style mbr-bold mbr-section-title3 display-5">John que</h2>
                <p class="nopadd">Designer - google.com</p>
            </div>
        </div>
    </div>
</div>

class="wrap" 中我必须div,一个用于图像,另一个用于文本内容。在普通浏览器视图中,图像和内容是从左到右的。这很好,很完美。

现在我希望在移动视图上(响应式)图像div 必须在顶部,内容div 必须在图像下方。

类似这样的东西:

【问题讨论】:

  • 使用媒体查询

标签: html css twitter-bootstrap twitter-bootstrap-3 responsive-design


【解决方案1】:

您使用媒体查询来做到这一点。

.wrap {
  display: flex;
  background: white;
  padding: 1rem 1rem 1rem 1rem;
  border-radius: 0.5rem;
  box-shadow: 7px 7px 30px -5px rgba(0,0,0,0.1);
  margin-bottom: 2rem;
}
.vcenter {
   margin: auto;
   margin-left: 10px;
}

.mbr-section-title3 {
  text-align: left;
}

.display-5 {
   font-family: 'Gotham-Book-Regular';
   font-size: 1.4rem;
}
.mbr-bold {
   font-weight: 700;
}

.display-6 {
   font-family: 'Gotham-Book-Regular';
   font-size: 1.4rem;
}

.fit100 {
  width: 100px;
  height: 100px;
}

.img-circle {
  border-radius: 50%;
}

@media screen and (max-width:767px){
  .wrap {
    flex-wrap: wrap;
    text-align: center;
  }
  .img-wrap{
    width:100%;
  }
  
  .img-wrap img {
    display: inline-block;
  }
  
  .mbr-section-title3 {
    text-align: center;
  }
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
    <div class="col-md-6">
        <div class="wrap">
            <div class="img-wrap">
                <img src="https://www.drupal.org/files/issues/default-avatar.png" class="img-circle fit100" alt="" title="">
            </div>
            <div class="text-wrap vcenter">
                <p class="mbr-fonts-style text1 mbr-text display-6">On Bawabba, you will find various types of services all under one roof. You can compare different profiles and contact the one that best suits your requirement directly wdslfjlksjdfk sdjfkljfsdkf sdk.</p>
                <h2 class="mbr-fonts-style mbr-bold mbr-section-title3 display-5">John que</h2>
                <p class="nopadd">Designer - google.com</p>
            </div>
        </div>
    </div>
</div>

【讨论】:

    猜你喜欢
    • 2013-11-25
    • 2017-07-01
    • 2011-04-26
    • 1970-01-01
    • 2017-12-29
    • 2020-10-21
    • 1970-01-01
    • 2016-09-15
    • 1970-01-01
    相关资源
    最近更新 更多