【问题标题】:only absolute positioning works in background image只有绝对定位在背景图像中有效
【发布时间】:2014-09-26 18:09:33
【问题描述】:

我正在尝试将背景放置到主页(即正文),并将图片与页面的中心右侧对齐,但是我找到的背景位置的所有参数(如中心右侧,或90% 50%) 没有效果,图片总是出现在左上角。只有绝对定位(如 background-position: 1000px 100px;)似乎有效果。

这是我的代码:

body
{
    background-image:url(images/bg.png);
    background-position:1000px 100px;
    background-repeat: no-repeat; 
    background-attachment: fixed;
    font-family:Verdana, Geneva, sans-serif;
    font-size:95%;
    color:#333;
    margin:0;
    width:100%;
    height:100%;
}

你知道这个问题的原因吗?

【问题讨论】:

  • center right 在您的代码上运行良好。 jsfiddle.net/H2X2L
  • 哦,没关系,我发现了问题:图像实际上包含很多空白...对不起,我犯了愚蠢的错误

标签: css background alignment


【解决方案1】:

试试这个

background: url(<images goes here>) no-repeat right center fixed

【讨论】:

  • 这字面意思是他发布的代码,但背景位置错误。
  • background-position:1000px 100px 如何等于 background-position:right center 到底?
  • 很公平,事实并非如此。但是,如果您重新阅读他说他已经尝试过background-position: center right 没有任何效果的问题。正如 Suresh Ponnukalai 指出的那样,他提供的代码确实有效,所以肯定还有其他东西在起作用。
猜你喜欢
  • 2021-05-19
  • 2013-05-19
  • 1970-01-01
  • 2012-04-15
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多