html - 调整浏览器大小时,前面的 div 会移动

标签 html css resize overflow

我正在做一个简单的网站。 在这个网站中,我有几个不同层的 div(一个在另一个前面等等)。 后面的两个 div 没有问题,但是当我调整浏览器大小时,前面的 div 会移动,我不希望这样。 奇怪的是后面的 div 是以相同的方式创建的。 所以基本上是什么搞乱了我的页面:#icone_esquerda#icone_direita。 下面是我的代码:

<style type="text/css">

#fundo{
    background-image:url("tileable_wood_texture_copy.png"); 
    background-repeat:repeat;
    position:fixed;
    width:100%;  
    height:100%;    
    top:0;
    left:0;
}

#frente{
    background-image:url("luinguica.png"); 
    background-repeat:no-repeat;
    background-position:top center;
    position:fixed;
    width:inherit;  
    height:inherit; 
    left: 0;
    top: 0;
    z-index:50;
}

#icone_esquerda{
    background-image: url("botao_facebook.png");
    background-position: bottom center;
    background-repeat: no-repeat;
    height: 50px;
    left: 45%;
    margin: -25px 0 0 -25px;
    position: fixed;
    top: 45%;
    width: 50px;
    z-index: 60;       
}

#icone_direita{
    background-image: url("botao_mail.png");
    background-position: bottom center;
    background-repeat: no-repeat;
    position: fixed;
    width: 50px;
    height: 50px;
    left: 53%;
    top: 45%;
    margin: -25px 0 0 -25px;
    z-index: 60;

</style>
</head>

<body>
  <div id="fundo">
     <div id="frente">    
         <a href="http://www.facebook.com/confrariadaempada">
            <div id="icone_esquerda">
            </div>
         </a>
         <a href="mailto:info@confrariadaempada.pt">
            <div id="icone_direita">
            </div>
         </a>
     </div>
   </div>
</body>

当我调整浏览器大小时,id 为 icone_esquerda 和 icone_direita 的 div 会移动! 谁能帮帮我?

提前致谢。

最佳答案

Fixed 应该根据屏幕将其保留在指定区域 - 它的位置、大小等。

Absolute 使其保持原样,无论位置或大小如何。

确实,应该很少(如果有的话)使用它们。最好学会根据需要使用带有 float 的 Relative 定位元素(当然要正确清除)。

关于html - 调整浏览器大小时,前面的 div 会移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16290141/

相关文章:

jquery - 在定位的 div 中从右侧悬停时滑动 Div

Java - 如何自动设置 img.getScaledInstance( ); 的宽度?

html - 尝试 "lock"表头行并挣扎

JavaScript 输入类型编号限制为值 1 和 2

HTML 页面无法加载 CSS 文件,找不到资源错误

css - Bootstrap 容器-流体与 float 元素发生碰撞

html - 文本溢出给出不需要的底部填充

javascript - 附加多个点击事件而不必重复自己

jquery - 我在我的站点 'full screen' 处平均划分了三个垂直元素,如何使我的中心元素为 'dominant' ?

javascript - 单击单选按钮时动态调整 iFrame 大小