html - 为什么下面的图像行是从上面移动的?
问题描述
由于某种原因,当将鼠标悬停在一个项目上时,整个下一行都会向下移动。
我输出查找数组中的尽可能多的项目,但我认为这并不重要。我确定问题出在 HTML 和 CSS 上。因此,它创建一个链接,然后使用 PHP 获取链接信息,然后绘制一个 div 并在其中包含一些标题文本,然后结束链接。
它从 CSS 中设置图像的比例padding-top
。我猜问题出在定位或转换上,但我不确定如何解决它。
echo '<div class="column">';
$backdrop = $results->poster_path;
if (empty($backdrop) && is_null($backdrop)){
$backdrop = '/images/no-gambar.jpg';
} else {
$backdrop = 'https://image.tmdb.org/t/p/w300'.$backdrop;
}
echo '<a href="movie.php?id=' . $id . '"><div class="imageFramed"
style="background-image:url('.$backdrop.');">';
echo '<h4 class="centered">'.$title.'</h4></div></a>';
echo '</div>';
YouTube 示例:这里。
对于 CSS:
.imageFramed {
position: relative;
width: 100%;
padding-top: 150%;
background-repeat: no-repeat;
background-size: cover;
border-radius: 5%;
max-width: 100%;
margin: 5%;
transition: transform .2s;
}
.imageFramed:hover {
border: 1px solid red;
-ms-transform: scale(1.01); /* IE 9 */
-webkit-transform: scale(1.01); /* Safari 3-8 */
transform: scale(1.03);
}
.imageFramed::after {
display: block;
position: relative;
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0, #000000 100%);
margin-top: -150px;
height: 150px;
width: 100%;
content: '';
border-radius: 5%;
}
.colour-overlay {
width: 100%;
border: 1px solid red;
}
/*Title*/
.centered {
position: absolute;
bottom: 25px;
left: 0;
width: 100%;
padding: 0px 10px 0px 10px;
z-index: 2;
}
解决方案
你必须指定属性box-sizing: border-box 在你的CSS:
块引用
html {
box-sizing: inherit;
}
body {
box-sizing: border-box;
}
推荐阅读
- speech-recognition - 为什么在梅尔谱图中使用 128 个梅尔波段?
- java - 使用 JPA 规范在 PostgreSQL jsonb 列中的所有值中搜索
- pandas - 如何删除多索引数据框熊猫中的特定行
- jvm - JVM 在哪里存储方法上的本地原始变量
- node.js - 运行从 Docker 中的 NPM 模块安装的后台 CLI
- java - imgproc 模块中某些函数的 OpenCV Android React Native 未知异常
- angular - 如何将 redirectTo 与包含参数的 url 一起使用?
- mysql - 选择所有日期最新的值
- html - XSL 擦除部分文本维护内部 html 标记
- javascript - 在 OnInit 中使用时方法不能删除 Map 元素?