html - 改变 float 元素的高度和 splinter 的网格布局

标签 html css

我需要一个简单的解决方案来解决这个 problem , float 布局被破坏的地方 当一个元素的高度发生变化时。例如:悬停事件触发附加元素(表格)出现。

代码如下:

HTML

<html lang="ru">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
      <main>
        <article class="main">
            <div class="zaglushka square">
              <figure><img src="http://lorempixel.com/g/200/200/" alt="Заглушка 15x15">
                <figcaption>
                  <h4>15x15</h4>
                  <table>
                    <tr>
                      <th>&lt;100шт</th>
                      <th>&lt;500шт</th>
                      <th>&gt;500шт</th>
                    </tr>
                    <tr>
                      <td>2₽</td>
                      <td>1.8₽</td>
                      <td>дог.</td>
                    </tr>
                  </table>
                </figcaption>
              </figure>
            </div>
            ...
            <div class="zaglushka square">
              <figure><img src="http://lorempixel.com/g/200/200/" alt="Заглушка 15x15">
                <figcaption>
                  <h4>15x15</h4>
                  <table>
                    <tr>
                      <th>&lt;100шт</th>
                      <th>&lt;500шт</th>
                      <th>&gt;500шт</th>
                    </tr>
                    <tr>
                      <td>2₽</td>
                      <td>1.8₽</td>
                      <td>дог.</td>
                    </tr>
                  </table>
                </figcaption>
              </figure>
            </div>
        </article>
      </main>
  </body>
</html>

CSS

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
}

main {
  width: 100%;
  padding: 0 .5rem;
}

.zaglushka {
  padding: .75rem;
  float: left;
  width: 20%;
  position: relative;
  z-index: 1;
}
.zaglushka table {
  position: relative;
  display: none;
}

.zaglushka:hover {
  z-index: 10;
  transform: scale(1.2);
}
.zaglushka:hover table {
  margin: 0 auto;
  background-color: grey;
  width: 90%;
  display: block;
}

section.catalog figure img {
  width: 90%;
}

什么是最简单的解决方案?

最佳答案

最简单的方法是不使用 float ,因为 float 不是用于布局,而是用于 float 元素。在布局中使用 float 会导致奇怪的行为并破坏布局。您应该通过内联 block 元素更改 float :

.zaglushka {
   display:inline-block;
}

看到它工作:

http://codepen.io/anon/pen/mePRbj

编辑

为了防止底部行移动,您应该使用边距,在这种情况下,在将鼠标悬停在框上时,您需要写入边距 -20%,因为您正在缩放到 +20%,而通过这种模式,您可以避免边距。

.zaglushka:hover {
   margin: -20% 0;
}

http://codepen.io/anon/pen/mePRbj

关于html - 改变 float 元素的高度和 splinter 的网格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32627420/

相关文章:

html - 有没有办法让 HTML 代码独立于 CSS 类名的变化?

php - Themosis 框架集合循环 - WordPress

javascript - 更改图像分辨率但保持物理尺寸

JavaScript - 根据正则表达式更改文本颜色

html - 在导航栏中添加部分

jquery - 我怎样才能摆脱悬停图像中的故障(Css3悬停效果)

html - 如何在 Objective-C 中解析字符串

javascript - 如何在 Canvas 上悬停时展开图像?

html - 为什么 object-fit 在 flexbox 中不起作用?

javascript - Safari 中出现此行为的原因是什么?