在调整屏幕大小时,问题集中在徽标上

问题描述 投票:0回答:2

我在这个网站上工作https://pure-cove-85477.herokuapp.com/正如你所看到的那样,它在中间有一个标志,当你调整屏幕大小时,它会改变它的大小和位置。我试图使用媒体查询来对其进行居中,随着屏幕尺寸的变化对其进行不同的定位,但是,并未在每个设备中正确居中,特别是如果您在具有横向模式的移动设备上使用它,徽标会突出于英雄图像。

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

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

我尝试使用bootstrap列,但它更混乱,媒体查询是我能想到的最好的解决方案,但它不能解决横向视图。

#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%;
    }
}
html css
2个回答
1
投票

你能试一下吗?

#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>

0
投票

你可以尝试使用display flex:

#hero{
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
img{
    max-width: 40%;
}

landscape

© www.soinside.com 2019 - 2024. All rights reserved.