允许内容与多列布局重叠

时间:2017-10-03 15:09:23

标签: html css css3 multiple-columns css-multicolumn-layout

我尝试允许内容重叠多列,忽略多列布局属性设置的边界。

问题在于,无论positionoverflow还是z-index,列都不会允许前一列的内容重叠并切断内容 - 就像溢出一样设为hidden

是否可以覆盖此行为?将鼠标悬停在代码段中的元素上,以查看此行为的示例。



body {
  background-color: silver;
}

.container {
  display: block;
  width: 50%;
  -webkit-column-count: 2;
  -moz-column-count: 2;
  column-count: 2;
  column-gap: 1em;
  -webkit-column-gap: 1em;
  -moz-column-gap: 1em;
}

.container div {
  position: relative;
  text-align: center;
  width: 100%;
  padding: 2em 0;
  background: #2980b9;
  color: white;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  break-inside: avoid;
  margin-bottom: 1em;
}

.container div:hover:after {
  content: 'I\'m overlapping!';
  position: absolute;
  width: 100%;
  color: black;
  background-color: white;
}

<div class="container">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

由于您使用的是:after,因此只需使用position:fixed:after只会将其放置在正确的位置,据我所知!为了使图像相对于视口定位,您还需要进行width:auto之类的调整,因为width:100%将占据屏幕的宽度,并且还需要z-index:3000来显示上面的文字divs。

body {
  background-color: silver;
}

.container {
  display: block;
  width: 50%;
  -webkit-column-count: 2;
  -moz-column-count: 2;
  column-count: 2;
  column-gap: 1em;
  -webkit-column-gap: 1em;
  -moz-column-gap: 1em;
}

.container div {
  position: relative;
  text-align: center;
  width: 100%;
  padding: 2em 0;
  background: #2980b9;
  color: white;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  break-inside: avoid;
  margin-bottom: 1em;
}

.container div:hover:after {
  content: 'I\'m overlapping, like a lot!!';
  position: fixed;
  width: auto;
  color: black;
  background-color: white;
  z-index:3000;
}
<div class="container">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>