简体   繁体   English

CSS:如果更改缩放,背景图像将不再对齐

[英]CSS: background-image not aligned anymore if I change zoom

If I change the zoom in my browser, the background image (the logo of my website) is positioned differently with respect to the other elements of the website. 如果更改浏览器中的缩放比例,则背景图片(网站徽标)相对于网站其他元素的位置会有所不同。

I'm using: 我正在使用:

background-image:url('tbs-logo.png');
background-repeat:no-repeat;
background-position: 92% 22%;

I was wondering if I can keep it aligned with the other elements, or I should change my html code instead to add the image with a tag. 我想知道是否可以使其与其他元素保持一致,否则我应该更改html代码以添加带有标签的图像。

Thanks. 谢谢。

I think you need to specify elements width and height with this background image. 我认为您需要使用此背景图片指定元素的宽度和高度。 I have checked it with simple code: 我已经用简单的代码检查了它:


<html>
<head><title>test</title>
<style type="text/css">
    #con{
        width: 500px;
        margin: 0 auto;
    }
    #img{
        width: 120px;
        height: 80px;
        background: url('ja2.jpg') 92% 22% no-repeat;
        float: left;
        border: 1px solid #000;
    }
</style>
</head>
<body>
    <div id="con">
        <div id="img"></div>
        <div>text tekst dfasdf
        saasdf dsaf dsa fas df sadf ' f
        af as dfa dsf
        ads f
         fa
         </div>
    </div>
</body>
</html>

when I zoom it, image still free in it's position 当我缩放它时,图像仍然在其位置自由

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM