html - 无法将徽标调整到特定高度
问题描述
我正在尝试将徽标合并到 HTML 页面中,但我似乎无法将其高度自动调整为 140 像素的最大高度。当我这样做时,徽标会被切掉。请参阅此示例:
.partner-logo {
background-image: url('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
margin-top: 20%;
max-height: 140px;
left: 96px;
z-index: 1;
background-repeat: no-repeat;
}
<div class="partner-logo">
</div>
如何确保此徽标可以具有 100% 的宽度,但最大高度仅为 140 像素?
解决方案
Please try applying background-size: contain
property to your css. background-size: contain
scales the image as large as possible without cropping or stretching the image.
For more about background-size
property see mdn
.partner-logo {
background-image: url('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
margin-top: 20%;
max-height: 140px;
left: 96px;
z-index: 1;
background-repeat: no-repeat;
background-size: contain;
background-position: center;
}
<div class="partner-logo">
</div>
推荐阅读
- oracle - 如何将oracle数据库从企业版迁移到标准版
- javascript - 如何从 Highcharter 股票图中提取最小和最大日期?
- jquery - 在列表中显示段落内容
- haskell - 如何在 GraalVM 上运行 Haskell?
- module - 无法加载模板文件
- java - ModelMapper 采用 toString 方法转换属性?
- c# - 补高阶函数
- ios - simdJson 如何在iOS程序中使用simdJson?(objective-C)
- python - 如何修改找不到元素的默认等待30秒?
- javascript - 将 SVG 作为 img 元素的 src 加载时会触发 load 事件吗?