【问题标题】:Column-Count Height Issue between Elements元素之间的列数高度问题
【发布时间】:2018-11-05 16:20:27
【问题描述】:

我遇到了 column-count CSS 属性的问题。

我将它与媒体查询一起使用,以使我的页面在移动设备上更具动态性。

但是,我的表单之间存在很大差距。 目前我正在将高度硬编码为“修复”,但这不是正确的方法。

有人遇到过这种问题吗?

@media only screen and (min-width: 400px) {
  .masonry {
    column-count: 1;
  }
}

@media only screen and (min-width: 700px) {
  .masonry {
    column-count: 2;
  }
}

.masonry {
  margin: 1.5em 0;
  padding: 0;
  column-gap: 1.5em;
  font-size: .85em;
  /*********Hard Coded Height Needs to be looked at***********/
  /* height:940px; */
}

.item {
  display: inline-block;
  background: #fff;
  padding: 1em;
  margin: 1px 0 1.5em;
  width: 100%;
  box-sizing: border-box;
  box-shadow: 2px 2px 2px 2px #ccc;
  border: 0px;
}

.legendTitle {
  font-size: 25px;
  font-weight: 500;
  font-family: 'Pacifico';
}
<form class="masonry">
  <fieldset class="item">
    <legend>
      Heading1
    </legend>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
  </fieldset>
  <fieldset class="item">
    <legend>
      Heading2
    </legend>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
  </fieldset>
  <fieldset class="item">
    <legend>
      Heading3
    </legend>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMakeLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled
      it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum
      passages, and more recently with desktop publishing software like Aldus PageMakeLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown
      printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release
      of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
  </fieldset>
</form>

<form class="masonry">
  <fieldset class="item">
    <legend>
      Heading4
    </legend>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
  </fieldset>
  <fieldset class="item">
    <legend>
      Heading5
    </legend>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
  </fieldset>
  <fieldset class="item">
    <legend>
      Heading6
    </legend>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
  </fieldset>
</form>

JSFiddle Demo

【问题讨论】:

标签: css column-count


【解决方案1】:

使用显示网格而不是列,它是密集设置:

糟糕,列在错误的 div 上 - 此处:

html:

<div id="wrapper">
    <form class="masonry">
      .....
    </form>
</div>

css:

    /* add a wrapper div */

    #wrapper {
      display:grid;
      /* no columns mentioned here because we put them in the @media calls at the bottom of the layout css */
      grid-gap: 1.5em;
      grid-auto-flow: dense;
    }
            .masonry {
        margin: 1.5em 0;
        padding: 0;
        /* column-gap: 1.5em; */
        font-size: .85em;
        /*********Hard Coded Height Needs to be looked at***********/
        /* height:940px; */
    }
    .item {
        display: inline-block;
        background: #fff;
        padding: 1em;
        margin: 1px 0 1.5em;
        width: 100%;
        box-sizing: border-box;
        box-shadow: 2px 2px 2px 2px #ccc;
        border: 0px;

    }
    .legendTitle{
      font-size: 25px;
      font-weight:500;
      font-family: 'Pacifico';
    }

    @media only screen and (max-width: 699px) {
        /* putting the grid columns count in the media call on the #wrapper NOT the .masonry inner div */
        #wrapper {
          /* column-count: 1; */
          grid-template-columns:1fr;
        }
    }

    @media only screen and (min-width: 700px) {
        /* putting the grid columns count in the media call on the #wrapper NOT the .masonry inner div */
        #wrapper {
            /* column-count: 2; */
            grid-template-columns:1fr 1fr;
        }
    }

更新小提琴:https://jsfiddle.net/0gtvj652/2/

很棒的网站:https://gridbyexample.com/examples/example1/

【讨论】:

  • 不幸的是,当转到移动设备时,这不会分成一列。
  • 嗨@RossSummerell - 我希望没有被低估^
  • 好吧,现在这一切都收费了,对不起,我太傻了。
猜你喜欢
  • 2021-09-06
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 2011-03-20
  • 1970-01-01
  • 2021-12-30
  • 1970-01-01
  • 2017-04-29
相关资源
最近更新 更多