浮动表格单元格右移除高度

时间:2016-09-13 12:54:36

标签: html css css3 media-queries

我有3个单元格|information| |two lines| |empty|和第二行|empty| |two lines| |information|的表格,我的媒体查询将这两个单元格更改为

|information||two lines|
|informatino||two lines|

问题在于,只要我将该div右移.verticalLine

,它们就会消失。

这是jsfiddle显示问题https://jsfiddle.net/fh6unb7q/

.side {
  width: 45%;
}
.verticalLine:before {
  content: "";
  display: block;
  position: absolute;
  border-left: 0.13em solid #90A4AE;
  border-right: 0.13em solid #90A4AE;
  height: 100%;
  width: 16%;
  margin-left: 42%;
  box-sizing: border-box;
}
.verticalLine {
  position: relative;
  width: 10%;
}
.tr {
  display: table-row;
}
.tc {
  display: table-cell;
}
.year {
  text-align: center;
  color: #607D8B;
}
/* Media Queries */

@media only screen and (max-width: 768px) {
  header h1 {
    font-size: 3rem;
  }
  .tr > div.side {
    display: none;
  }
  .tr > div.verticalLine {
    float: right;
  }
  .tr > div.year {
    float: right;
  }
  .tr > a {
    float: left;
  }
  .side {
    width: 90%;
  }
}
<div style="display: table;">
  <div class="tr">
    <a class="tc side" target="_blank" href="#">
      <h3>test test test test test test test test test test test test test </h3>
    </a>
    <div class="tc verticalLine">
    </div>
    <div class="tc side"></div>
  </div>

  <div class="tr">
    <div class="tc side"></div>
    <div class="tc verticalLine">
    </div>
    <a class="tc side" target="_blank" href="#">
      <h3>test test test test test test test test test test test test test </h3>
    </a>
  </div>

</div>

编辑:使用flex更新代码 - https://jsfiddle.net/fh6unb7q/1/ HTML:

<div style="display: flex;">
    <a class="side" target="_blank" href="#">
      <h3>test test test test test test test test test test test test test </h3>
    </a>
    <div class="verticalLine">
    </div>
    <div class="side"></div>
</div>

<div style="display:flex">
    <div class="side"></div>
    <div class="verticalLine">
    </div>
    <a class="side" target="_blank" href="#">
      <h3>test test test test test test test test test test test test test </h3>
    </a>
</div>

CSS:

.side {
  width: 45%;
}

.verticalLine:before {
  content: "";
  display: block;
  position: absolute;
  border-left: 0.13em solid #90A4AE;
  border-right: 0.13em solid #90A4AE;
  height: 100%;
  width: 16%;
  margin-left: 42%;
  box-sizing: border-box;
}

.verticalLine {
  position: relative;
  width: 10%;
}



/* Media Queries */

@media only screen and (max-width: 768px) {
  div.side {
    display: none;
  }
  div.verticalLine {
    float: right;
  }

  a {
    float: left;
  }
  .side {
    width: 90%;
  }
}

正如你所看到的那样,虽然||仍未正确对齐在执行媒体查询后仍然可见。

我希望它像这样对齐

|information||two lines|
|informatino||two lines|

1 个答案:

答案 0 :(得分:1)

像这样:?

https://jsfiddle.net/uce9hp9n/

然后只需将flex-direction: row-reverse;添加到第二行容器中。

评论后的补充/编辑:

使用flex解决方案,您可以为每个行容器分配相同的类,并为该类创建CSS规则。然后创建另一个规则:

.my_row { 
  display:flex; 
}
.my_row:nth-child(even): { 
  flex-direction:row; 
}

这将颠倒每第二行的顺序。