简体   繁体   English

为什么背景位置不起作用?

[英]Why isn't background-position working?

I don't often use background-position, so maybe I'm not doing this correctly, but my css rule is not taking effect. 我不经常使用背景位置,因此也许我没有正确执行此操作,但是我的CSS规则未生效。

background-position:right 353px bottom 20px;

Here's the code: 这是代码:

HTML HTML

<h1> 
    <a href="#">
        <img src="/images/silver-corner-logo.jpg" id="site-title" />
    </a>
</h1>

CSS CSS

h1 {
    width:80%;height:154px;
    min-width:353px;
    margin:0;padding:0;
    text-align:right;
    background-color:#A8A9AD;
    background-image:url("/images/top-left.jpg");
    background-repeat:no-repeat;
    background-position:right 353px bottom 20px;
}
#site-title {
    margin:0;padding:0;
    display:block;
    width:353px;
    float:right;
}

EDIT 编辑

It Occurs to me that maybe I should describe what it is I am trying to accomplish. 我想到也许我应该描述一下我要完成的工作。

Within my h1, I have a logo (width 353). 在我的h1内,我有一个徽标(宽度353)。
The h1 may become larger than 353 depending on the screen size. 根据屏幕尺寸,h1可能会大于353。

In this case I want a background image to display to adjacent (left) to the img so that it will nicely fade into the solid background color. 在这种情况下,我希望背景图像显示在img的相邻位置(左侧),以便它能很好地淡化为纯背景颜色。

What browser are you using? 你使用的是什么浏览器? Four values for background-position is only supported in a couple of them (Firefox, Chrome and Safari do NOT support it). 仅其中几个支持四个background-position值(Firefox,Chrome和Safari不支持)。 Documented here. 记录在这里。

That's not the proper syntax for background-position , as indicated by this documentation . 本文档所示, 不是background-position的正确语法。

right and bottom do not have numeric arguments, but stand alone. rightbottom没有数字参数,但独立存在。

background-position: right 353px bottom 20px; background-position: 右353px下20px;

It is confusing, following shows how to use background:position. 令人困惑,下面显示了如何使用background:position。

Optionsof position 位置选项

left top
left center
left bottom
right top
right center
right bottom
center top
center center
center bottom

If you only specify one keyword, the other value will be "center" 如果您仅指定一个关键字,则另一个值为“ center”

x% y%   

The first value is the horizontal position and the second value is the vertical. 第一个值是水平位置,第二个值是垂直位置。 The top left corner is 0% 0%. 左上角为0%0%。 The right bottom corner is 100% 100%. 右下角是100%100%。 If you only specify one value, the other value will be 50%. 如果仅指定一个值,则另一个值将为50%。 . Default value is: 0% 0% 默认值为:0%0%

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

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