Html 背景位置不工作

Html 背景位置不工作,html,css,Html,Css,我找不到背景工作。我试着把代码放在我能想到的任何地方!!!有什么想法吗???谢谢 我的html是 <div class="container"> <div class="inner"></div> </div> 您正在对背景图像使用速记,因此应该在background:style中包含位置 .inner { border: 1px solid; height: 160px; width: 320px;

我找不到背景工作。我试着把代码放在我能想到的任何地方!!!有什么想法吗???谢谢

我的html是

<div class="container">
      <div class="inner"></div>
</div>

您正在对背景图像使用速记,因此应该在background:style中包含位置

.inner {
    border: 1px solid;
    height: 160px;
    width: 320px;
    background: url("welcome-small.png") no-repeat 50% 50% green;
}

您正在对背景图像使用速记,因此应该在background:style中包含位置

.inner {
    border: 1px solid;
    height: 160px;
    width: 320px;
    background: url("welcome-small.png") no-repeat 50% 50% green;
}

使用
margin
将您的
容器居中
并删除您拥有的额外
背景
属性

.container {
    width: 80%;
    background-color: red;
    text-align: center;
    margin: 0 auto;
}
这是您更新的代码笔,显示它居中。

利用
边距
将您的
容器居中
,并删除您拥有的额外
背景
属性

.container {
    width: 80%;
    background-color: red;
    text-align: center;
    margin: 0 auto;
}
这是您更新的代码笔,显示它居中。

您的
background
属性重写了背景位置,请参见此 这是因为默认情况下,后台也会将后台位置设置为
0

.inner {
    border: 1px solid;
    height: 160px;
    width: 320px;

    background: green url("http://images.visitcanberra.com.au/images/canberra_hero_image.jpg") no-repeat;
    background-position: 20% 50%;
}
只需使用
background
属性下面的
background
属性即可
此外,如果希望内部水平居中,请使用“自动边距”:

.container{
宽度:80%;
背景色:红色;
背景位置:中心;
文本对齐:居中;
}
.内部{
边框:1px实心;
高度:160px;
宽度:320px;
保证金:自动;
背景:绿色url(“http://images.visitcanberra.com.au/images/canberra_hero_image.jpg)无重复;
背景位置:20%50%;
}

您的
background
属性重写了背景位置,请参见此 这是因为默认情况下,后台也会将后台位置设置为
0

.inner {
    border: 1px solid;
    height: 160px;
    width: 320px;

    background: green url("http://images.visitcanberra.com.au/images/canberra_hero_image.jpg") no-repeat;
    background-position: 20% 50%;
}
只需使用
background
属性下面的
background
属性即可
此外,如果希望内部水平居中,请使用“自动边距”:

.container{
宽度:80%;
背景色:红色;
背景位置:中心;
文本对齐:居中;
}
.内部{
边框:1px实心;
高度:160px;
宽度:320px;
保证金:自动;
背景:绿色url(“http://images.visitcanberra.com.au/images/canberra_hero_image.jpg)无重复;
背景位置:20%50%;
}


背景属性是所有背景属性的缩写。它覆盖了先前声明的任何已设置的单独属性

也许这里最简单的解决方案就是在速记之后将背景位置设置移动到

.inner {
    border: 1px solid;
    height: 160px;
    width: 320px;
    background: green url("welcome-small.png") no-repeat;
    background-position: 50% 50%;
}

background
属性是所有背景属性的简写。它覆盖了先前声明的任何已设置的单独属性

也许这里最简单的解决方案就是在速记之后将背景位置设置移动到

.inner {
    border: 1px solid;
    height: 160px;
    width: 320px;
    background: green url("welcome-small.png") no-repeat;
    background-position: 50% 50%;
}

抱歉-我没有看到你的答案-当我收到回复时,网站没有给我发电子邮件,所以我没有意识到(我在别处得到了答案)

基本上-我需要的是margin:auto(因为我在div中嵌套了一个div)。知道怎么做很容易!!!;-)


谢谢你们的帮助。大雁在钱上是对的

对不起-我没有看到你的答案-当我收到回复时,网站没有给我发电子邮件,所以我没有意识到(我在别处得到了答案)

基本上-我需要的是margin:auto(因为我在div中嵌套了一个div)。知道怎么做很容易!!!;-)


谢谢你们的帮助。大雁在钱上是对的

顺便问一下,哪个背景位置你不能工作?
.container
.internal
或两者?你想把
.container
放在中间吗?顺便问一下,哪个
背景位置
不能工作?
.container
.internal
或两者?您希望将
.container
放在中心位置吗?欢迎使用堆栈溢出!你能解释一下为什么这个代码能回答这个问题吗?代码唯一的答案是,因为他们不教解决方案。欢迎使用堆栈溢出!你能解释一下为什么这个代码能回答这个问题吗?代码唯一的答案是,因为他们不教解决方案。