html - 调整屏幕大小时问题居中 Logo

标签 html css

我正在这个网站上工作 https://pure-cove-85477.herokuapp.com/ 如您所见,它中间有一个 Logo ,当您调整屏幕大小时,它会更改其大小和位置。我曾尝试使用媒体查询将其居中,随着屏幕尺寸的变化将其定位不同,但是,在每台设备上都无法正确居中,特别是如果您在横向模式的移动设备上使用它, Logo 会从英雄图像中突出来.

我使用 https://www.responsinator.com/检查那个问题。

我的问题是,是否有一个简单的 DRY 解决方案?

我尝试使用 bootstrap 列,但它更困惑,媒体查询是目前我能想到的最佳解决方案,但它不能解决横向 View 。

#hero img {
    transform: scaleX(-1);
    width: 50%;
    position: absolute;
    top: 25%;
    right: 25%;
}

@media (min-width: 576px) {
    #hero img {
        transform: scaleX(-1);
        max-width: 40%;
        position: absolute;
        top: 25%;
        right: 30%;
    }
}
@media (min-width: 768px) {
    #hero img {
        transform: scaleX(-1);
        max-width: 30%;
        position: absolute;
        top: 23%;
        right: 35%;
    }
}
@media (min-width: 992px) {
    #hero img {
        transform: scaleX(-1);
        max-width: 20%;
        position: absolute;
        top: 30%;
        right: 40%;
    }
}
@media (min-width: 1200px) {
    #hero img {
        transform: scaleX(-1);
        max-width: 20%;
        position: absolute;
        top: 30%;
        right: 40%;
    }
}

最佳答案

你能试试这个吗。

#hero img {
    transform: translate(-50%, -50%);
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
}
<div id="hero">
  <img src="https://res.cloudinary.com/gnprojects/image/upload/v1546601197/Website%20images/logo_la_tiendita_del_pan.png" />
</div>

关于html - 调整屏幕大小时问题居中 Logo ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54667639/

相关文章:

javascript - setInterval 之后重新调用 iframe

html - 强制 SVG 根据百分比高度调整大小

html - 良好做法 : Pagination links in html lists?

javascript - 将数据发布到 .html 时如何隐藏 JQuery 中的元素?

javascript - 在 jQuery DataTables 中使用 sDom 删除搜索框

javascript - 显示/隐藏层 onclick 不一致

html - CSS 背景图片不会加载 Django 2.1.2

javascript - 获取使用 calc 等表达式的 CSS 变量的计算值

javascript - 2 内联 fancybox,第二个 fancybox 出现错误 "The requested content cannot be loaded"

html - Bootstrap 在未显示占位符时选择标签