【问题标题】:50% Sections Won't Stack On Mobile50% 的部分不会在移动设备上堆叠
【发布时间】:2017-03-22 11:43:17
【问题描述】:

编辑 我更正了一个错字并更新了 JSFiddle 和这篇文章以反映这一变化。标题应该占据 100% 的高度,但事实并非如此。仍在寻找想法。

这在桌面上看起来就像我想要的那样。我不明白为什么在移动设备上它不会占据 100% 的高度并堆叠在一起。标题也失去了彩色背景。 Here's the JSFiddle

HTML

    <div class="about-header">
      <h2>Headline</h2>
    </div>

    <div class="about-section">

      <div class="about-text">
        <p>The first chunk of text to let users know they gotta read a 
         little bit. If they want. It's not mandatory or anything.</p>

        <p>The second group of text, a nice chunk of descriptive text that 
        explains some more about this website. It really hopes you can help 
        me troubleshoot this problem that I am facing.</p>

        <p>Another grouping of text goes right in this little section here 
        that should go on for a while.</p>
     </div><!-- END ABOUT TEXT -->

    </div> <!-- END ABOUT SECTION-->
 </section>
</div><!-- END CONTAINER -->

CSS

*{
  margin:0;
  padding:0;
}

html{
  font-size:62.5%;
}

html,
body{
  height:100%;
  background-color:#FFF;
  color:#000;
  font-family:"Arial", "Helvetica", sans-serif;
  font-size:12px;
  font-size:1.2rem;
}

.container{
  width:100%;
  height:100%;
 }

.container *{
  box-sizing:border-box;
}

.row{
  min-width:85%;
  margin:0 auto;
}

.row:before,
.row:after{
  content:"";
  display:table;
  clear:both;
}

#about{
  height:100%;
}

.about-header{
  width:100%;
  height:100%;
  background-color:lightblue;
  position:relative;
}

.about-header h2{
  display:table-cell;
  vertical-align:middle;
  text-align:center;
  text-transform:uppercase;
}

.about-section p{
  font-size:1rem;
  padding-left:1.2rem;
  padding-right:3rem;
  padding-bottom:1.5rem;
}

.about-text{
  display:table-cell;
  vertical-align:middle;
}

.about-section{
 width:100%;
 height:100%;
 position:relative;

}

/**** MEDIA QUERY****/
@media all and (min-width:500px){

.about-section{
  width:50%;
  height:100%;
  background-color:#FFF;
  left:50%;
  display:table;
  position:absolute;
}

.about-header{
  width:50%;
  height:100%;
  background-color:lightblue;
  right:50%;
  display:table;
  position:absolute;
}

}

【问题讨论】:

    标签: html css layout height responsive


    【解决方案1】:

    你有一个错字。

    .about-head{
        width:100%;
        height:100%;
        background-color:lightblue;
        position:relative;
    }
    

    应该是:

    .about-header {
        width:100%;
        height:100%;
        background-color:lightblue;
        position:relative;
    }
    

    【讨论】:

    • 感谢您指出这一疏忽。我做出了改变。这解决了颜色和格式。 div 并没有像在桌面上那样占据 100% 的高度。
    • 啊,你的行在移动端没有高度。尝试将其设置为 100%。
    • 如果你想让 h2 居中显示不能设置为表格单元格,我应该添加。
    • 表格单元格是我如何让它在桌面上的浅蓝色 div 中居中。我希望它在移动设备上做同样的事情,只是堆叠在也是 100% 高度的白色文本 div 上。
    • 如果您希望 h2 标签在桌面居中,只需在媒体查询中添加 dispaly: table-cell。如果您希望它们在移动设备和桌面设备中垂直对齐并居中,请确保 .about-header 具有 display: table。如果你不关心 Internet Explorer,你可以考虑使用 flex 来堆叠和对齐 div。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 1970-01-01
    • 2017-09-28
    • 2014-09-03
    相关资源
    最近更新 更多