【问题标题】:CSS positioning relative to total page area相对于总页面区域的 CSS 定位
【发布时间】:2012-01-05 16:02:59
【问题描述】:

我希望我能解释一下。

我有一个图像“卡”在浏览器窗口的右侧,所以当浏览器窗口改变大小时,它仍然卡在右侧。我使用的风格是:

style="position :absolute; top :4px; right :4px"

我的最小身体宽度也为 1024 像素:

body 
{
    min-width: 1024px;
}

这一切都很好,直到窗口的大小调整到小于 1024,然后图像仍然粘在窗口的右侧。但我希望它贴在整个页面区域的右侧。如果你明白我的意思。

谢谢,

AJ

【问题讨论】:

    标签: html css


    【解决方案1】:

    css 位置属性基于定位的父级计算。如果您的图像没有任何已定位的父级,则绝对值将相对于屏幕。你应该可以通过放置 position:relative; 来解决这个问题。在你的 css 中作为 body 或通过使用 position:relative 将所有内容包装在正确大小的 div 中;

    【讨论】:

      【解决方案2】:

      您可以在包含您的图片的 div 中使用 position: relative 成功,代码如下:

      <div style="position:relative; min-width: 1024px">
          <div style="position: absolute; top: 10px; right: 4px; width: 20px; height: 20px; background-color: red"></div>
      
          <div style="width: 1024px; margin: auto 0px; height: 400px; background-color: #AAA">&nbsp;</div>
       </div>
      

      Example here: http://jsfiddle.net/7jafS/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-23
        • 2013-06-22
        • 2023-03-30
        相关资源
        最近更新 更多