Css 如何将此设置为中心<;部门>;

Css 如何将此设置为中心<;部门>;,css,html,center,Css,Html,Center,我想把这个部门的背景放在中心。当我将margin:auto添加到css.div.background img时,它会将图像居中,但不会显示其余的图像。这是我的css,如果有人能帮我,我会非常感激 <style type="text/css"> body { margin: auto; padding: 0; width: 100%; text-align: center; } .fondolineas { background-image: u

我想把这个部门的背景放在中心。当我将
margin:auto
添加到css
.div.background img
时,它会将图像居中,但不会显示其余的图像。这是我的css,如果有人能帮我,我会非常感激

<style type="text/css">
body {
    margin: auto;
    padding: 0;
    width: 100%;
    text-align: center;
}
.fondolineas {
    background-image: url(fondo.gif);
    background-repeat: repeat-x;
}
.demo-ad-top{
    margin:20px 0;
}
.gradient {
    background-image: -webkit-gradient(  linear,  left bottom,  left top,  color-stop(0.28, rgb(255,201,116)),  color-stop(0.64, rgb(228,143,10)) );
    background-image: -moz-linear-gradient(  center bottom,  rgb(255,201,116) 28%,  rgb(228,143,10) 64% );
    width:300px;
    height:150px;
    padding:5px;
}

h1 {
    font:bold 14px/1.5em "Trebuchet MS", Trebuchet, Arial, Verdana, Sans-serif;
    text-transform:uppercase;
}
div.background {
    position: absolute;
    left: auto;
    top: auto;
    z-index: -1;
    alignment-adjust: central;
    background-position: center;
    text-align: center;
}
div.background img {
    position:fixed;
    list-style: none;
    left:auto;
    top:auto;
}
div.background ul li.show {
    z-index:500
}
.content {
    width:1200px;
    margin-left:auto
    margin-right:auto
    background:#fff;
    padding:30px;
}
</style>

身体{
保证金:自动;
填充:0;
宽度:100%;
文本对齐:居中;
}
丰多利纳斯先生{
背景图片:url(fondo.gif);
背景重复:重复-x;
}
.演示广告顶部{
利润率:20px0;
}
.梯度{
背景图像:-webkit渐变(线性、左下、左上、颜色停止(0.28,rgb(255201116))、颜色停止(0.64,rgb(228143,10));
背景图像:-莫兹线性梯度(中底,rgb(255201116)28%,rgb(228143,10)64%);
宽度:300px;
高度:150像素;
填充物:5px;
}
h1{
字体:粗体14px/1.5em“投石机MS”,投石机,Arial,Verdana,无衬线;
文本转换:大写;
}
部门背景{
位置:绝对位置;
左:自动;
顶部:自动;
z指数:-1;
校准调整:中央;
背景位置:中心;
文本对齐:居中;
}
部门背景图像{
位置:固定;
列表样式:无;
左:自动;
顶部:自动;
}
节目背景{
z指数:500
}
.内容{
宽度:1200px;
左边距:自动
右边距:自动
背景:#fff;
填充:30px;
}
试试这个

background:no-repeat;
background-image:url(../Images/Home/Banner.png);
background-position:center;
要用你的尺寸来容纳或拉伸背景,你必须使用这个

background-size: contain;

您的图像将不会响应将其边距设置为
自动
,因为您使用的是
位置:固定。相反,通过将
left
right
设置为
0
将其居中

div.background img {
    list-style: none;
    position: fixed;
      left: 0;
      right: 0;
      top: 0;
}

由于您将
img
s固定在屏幕上,
margin:auto
不会将其居中放置。请尝试以下方法:

div.background img {
    position:fixed;
    left:50%;
    top:auto;
    margin-left:-600px; /* Half of the image's width */
}

用这个来准备问题:@Bibi,你在
.content
中少了几个分号。哇!你们太棒了,非常感谢!!这很有效。继续摇摆:)我还在学习。热烈拥抱!嘿谢谢你的回答,我终于可以做到了。吻。嘿,夜火猫,谢谢你的帮助!如果可以的话,我会给你们分数,但我还不能,因为我是新来的。但你们真的帮了我,我很高兴:)谢谢!没问题。如果你觉得我的答案(以及其他答案)值得投票,那么等你有足够的声誉时再来。我很高兴我们能帮忙。