简体   繁体   English

<div>响应正方形网格的布局问题

[英]<div> layout issue with a grid of responsive squares

I have a grid of responsive squares over a colored background <div> . 我在彩色背景<div>有一个响应正方形网格。 What am I doing wrong that the bottombar <div> isn't below the grid of squares and instead inline with the top of the background? 我的bottombar <div>不在正方形网格的下方,而是与背景的顶部bottombar ,这是我做错了吗?

CSS: CSS:

#container {
    width: 100%;
    height: 100%;
    position: relative;
}

#squarecontainer, #infoi {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

#squarecontainer {
  z-index: -1;
  background-color:yellow;
}

#infoi {
   z-index: 2;
   background-color:blue;
}

.square {
  -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit  */
  -moz-box-sizing: border-box;    /* Firefox, other Gecko         */
  box-sizing: border-box; 
  float:left;
  position:relative;
  width:50%;
  padding-bottom:50%;
  border: 1px solid #FFF;
  background-color:#7F3F98;
  /* RGBa with 0.9 opacity */
  background-color: rgba(127, 63, 152, 0.9);
  /* For IE 5.5 - 7*/
  filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#E67F3F98, endColorstr=#E67F3F98);
  /* For IE 8*/
  -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#E67F3F98, endColorstr=#E67F3F98)";
  overflow:hidden;
}

.table{
    display:table;
    height:100%;
    width:100%;
}

.content {
  position:absolute;
  height:90%;
  width:90%;
  padding: 5%;
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  font-size:160%;
  font-size:5vw;
  color: #fff;
}

#cell4 {
  visibility:hidden;
}

#bottombar {
  clear:both;
  position:relative;
}

HTML: HTML:

<div id="topbar">Topbar information here</div>
<div id="container">
    <div id="squarecontainer">
      <div class="square" id="cell1">
        <div class="content">
        Div 1
        </div>
      </div>
      <div class="square" id="cell2">
        <div class="table">
        <div class="content">
        Div 2
        </div>
        </div>
      </div>
      <div class="square" id="cell3">
        <div class="content">
        Div 3
        </div>
      </div>
      <div class="square" id="cell4">
        <div class="content">
        Div 4
        </div>
      </div>
    </div>
    <div id="infoi">Floating text here</div>
</div>
<div id="bottombar">Bottombar info here</div>

jsfiddle: http://jsfiddle.net/8o643xqx/7/ jsfiddle: http : //jsfiddle.net/8o643xqx/7/

As GCyrillus asked in his comment; 正如GCyrillus在他的评论中所问的那样; Do you really need absolute positioning? 您真的需要绝对定位吗?

I removed it, and added overflow: hidden; 我删除了它,并添加了overflow: hidden; to #squarecontainer , and everything seems to be working as expected. #squarecontainer ,一切似乎都按预期工作。

http://jsfiddle.net/8o643xqx/9/ http://jsfiddle.net/8o643xqx/9/

EDIT : Basically the same thing with this one. 编辑 :与此基本相同的事情。 How's this? 这个怎么样?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM