html - 中心标志与背景图像一起显示
问题描述
我正在创建一个仅包含徽标的标题。我将此徽标显示为带有背景图像的 DIV,而不是图像。图像在桌面上很好,左边距为 2vh。我试图将它集中在移动设备上,但由于某种原因它不起作用。
.logoholder {
margin-left: auto;
margin-right: auto;
}
.logo {
height: 8vh;
margin-top: 1vh;
margin-bottom: 1vh;
margin-left: 2vh;
background-image: url("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png");
background-repeat: no-repeat;
}
@media only screen and (max-width: 500px) {
.logo {
height: 8vh;
margin-top: 1vh;
margin-bottom: 1vh;
margin-left: auto;
margin-right: auto;
background-image: url("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png");
background-position: center
background-repeat: no-repeat;
}
}
<div class="logoholder">
<a href="/">
<div class="logo">
</div>
</a>
</div>
任何为什么这不起作用的想法将不胜感激。
提前致谢。
解决方案
我确信这样做是有理由的,但就 css 的实际工作方式而言,可能没有很好的理由。通过使用实际图像并将其绝对定位在 div 的中心并将任何其他内容分层放在顶部,您可能会获得更好的结果。这将允许您随意调整图像大小并保持所需的任何位置。
推荐阅读
- python - python中的Zip运算符
- python - ValueError:检查目标时出错:预期dense_2的形状为(1,),但数组的形状为(50,)
- ionic-framework - IONIC 3 的本地通知插件安装
- python - 如何在python中可视化复杂的图形?
- sql - 多列和多表内连接
- python - 针对不在 [0,1] 内的概率调试神经网络 dropout 问题
- azure-devops - 如何在 Scrum 模板下提取 Azure DevOps 中的人员工作量报告?
- indexeddb - 浏览器扩展可以下载现成的 IndexedDB 数据库吗?
- python - 从元组字典中获取最大值
- c++ - 函数范围的静态变量如何导致与共享库中函数代码的未来使用不兼容