html - 图像与内容重叠在容器顶部
问题描述
在卡片顶部放置图像并在其下方放置内容的最佳方式是什么?
我尝试过负利润率,但我对这种方法没有运气。
这是我对代码的尝试
.card {
text-decoration: none;
margin-right: 20px;
text-align: center;
}
.card__section {
overflow: hidden;
padding-bottom: 50px;
display: block;
position: relative;
}
.card__inner {
background: black;
padding: calc(35px + 30%) 35px 35px;
color: white;
width: 100%;
display: block;
position: relative;
}
.card__image {
width: 80%;
height: auto;
margin: 0 auto -30%;
position: relative;
z-index: 1;
}
<a href="#" class="card">
<section class="card__section">
<img
class="card__image"
src="http://via.placeholder.com/340x220"
alt=""
/>
<div class="card__inner">
<h1>
This is a static template, there is no bundler or bundling
involved!
</h1>
</div>
</section>
</a>
解决方案
你需要在css下面添加
.card__section {
overflow: visible;
}
.card__image {
margin-bottom: 20px;
margin-top: -100px;
}
section.card__section {
margin-top: 60px;
}
并将您的图像放入card__inner
div
见https://codesandbox.io/s/card-hover-5n0yf?file=/index.html:450-461
希望这可以帮助
推荐阅读
- python - 将包含字典列表的 pandas 数据框列解压缩到新列中
- c# - 在 C# 中读取 XML 文档的嵌套元素
- python - Python将带有多行的常规函数移动到lambda
- gtk - gtk绘图区可以用css设置样式吗?
- html - 如何在 HTML 中使用文本本身作为超链接?
- visual-studio - AzureDevOps - 如果之前的运行没有产生工件,DownloadPipelineArtifact@2 不会下载工件
- arrays - 使用 Powershell 计算多维数组
- python - 如何让硒处理崩溃或崩溃后退出循环
- android-studio - 来自 kotlin (Android Studio) 中 activity_main.xml 对象的未解析引用
- python - 为什么单词之间的空格不显示