我需要一个简单的解决方案来解决这个 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><100шт</th>
<th><500шт</th>
<th>>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><100шт</th>
<th><500шт</th>
<th>>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;
}
关于html - 改变 float 元素的高度和 splinter 的网格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32627420/