html - 为什么叠加的图片和标志+文字不起作用?
问题描述
我必须将徽标的分辨率更改为至少能够看到徽标(格式为 3400x1716)到 99x50 以重叠图片并添加带有徽标的文本。我将应该叠加的图片设置为 300 高度和 100% 宽度以填充页面的其余部分,但这在我的代码中显示。最终产品将是我将能够将鼠标悬停在图片/徽标上并显示文本。
我的问题是我看不到徽标,也看不到应该叠加图片的文字。
总共有 12 张图片,有 12 种不同的文字,但标志相同。
.portfolio-items-wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.portfolio-item-wrapper {
position: relative;
}
.portfolio-img-background {
height: 300px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.img-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding-left: 100%;
padding-right: 100%;
}
<div class="content-wrapper">
<div class="portfolio-items-wrapper">
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background- image:url(images/portfolio1.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/logos/thought.png">
</div>
<div class="subtitle">
Using a different approach than the NORM!
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background- image:url(images/portfolio2.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/logos/thought.png">
</div>
<div class="subtitle">
Everything starts with a THOUGHT!
</div>
</div>
</div>
</div>
</div>
解决方案
您可以使用您开始使用的方法,即为您的父容器元素设置背景图像,然后您可以使用 flexbox 定位文本和徽标元素。
img {
width:50px;height:50px;
}
div {
background-image:url('https://static-cse.canva.com/image/1578/RoyalBlue_Set1_23.5dfc6872.png');
background-size:contain;
background-repeat:no-repeat;
background-position:center center;
width:300px;height:300px;
display:flex;align-items:center;flex-direction:column;justify-content:center;
color:#FFF;font-size:36px;
}
<div>
<img src="https://assets.codepen.io/5200861/internal/avatars/users/default.png">
<h3>some text here</h3>
</div>
推荐阅读
- google-chrome-extension - 是否可以在 devtools 或 inspectedwindows 中访问 Web 串行端口?
- opencv - OpenCV:“相机校准”为什么非平面校准装置需要初步猜测?
- benchmarking - 在 mlr3 的基准测试中使用预定义的训练和测试集
- java - 外部类实现接口的内部类中实现的方法
- flutter - 从底部选择文本时可滚动的 SelectableText 自动滚动到小部件顶部
- keycloak - 使用 Keycloak 会话存储跨多个身份验证会话存储值
- xml - 是否可以使用 xslt 保留第一个打开标签和最后一个关闭标签?
- android - Kotlin 标准函数未解析参考 Android Studio
- android - 如何在 Flutter 中使用 ThemeData 在 Flutter 中手动设置暗模式?
- netbeans - 无法调用 java.sql.Connecton.preparestatement(String),因为 con 为空