Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html CSS-在自动调整大小的容器中居中标题背景图像并自动调整大小_Html_Css - Fatal编程技术网

Html CSS-在自动调整大小的容器中居中标题背景图像并自动调整大小

Html CSS-在自动调整大小的容器中居中标题背景图像并自动调整大小,html,css,Html,Css,我的css容器当前的静态宽度为900px,并且有一个相同宽度的标题背景图像。我想使容器自动调整大小,并在居中的标题背景图像的任一端具有纯色自动调整大小区域 谢谢 西葫芦 这就是我一直在做的事情 /* ------------------------------ global styles ------------------------------ */ body { margin: 0; padding: 0; font: Verdana, Geneva, sans-serif; text-

我的css容器当前的静态宽度为900px,并且有一个相同宽度的标题背景图像。我想使容器自动调整大小,并在居中的标题背景图像的任一端具有纯色自动调整大小区域

谢谢

西葫芦

这就是我一直在做的事情

/* ------------------------------
global styles
------------------------------ */

body
{
margin: 0;
padding: 0;
font: Verdana, Geneva, sans-serif;
text-align: center;
color: #F0F0F0;
background: #FFFFFF;
}

a:link { color: #B52c07; }
a:visited { color: #b93411; }
a:focus { color: #000; }
a:hover { color: #7d8206; }
a:active { color: red; }
h1, h2, h3, h4, h5, h6 { margin: 0 0 .5em; }

h2
{
color: #000000;
font: 140% Verdana, Geneva, sans-serif;
}

h2 a { text-decoration: none; }

h3
{
color: #000000;
font: 110%  Verdana, Geneva, sans-serif;
}

/* ------------------------------
container styles
------------------------------ */

#container
{
margin: 1em auto;
width: 100%;
text-align: center;
background: #fff;
border: 1px solid #000000;
}

/* ------------------------------
header styles
------------------------------ */

#headertop
{
position:relative;
height: 178px;
width: 100%;
text-align:center;
/*background-position:center;
/*position:static;*/
background-image:url(../images/Header.jpg);
/*background-position:center;
/*background: url(../images/Header.jpg);*/
background-color:#000000;
border-bottom: 0px solid #fff;
}

将标题背景色设置为所需的纯色,然后将背景图像居中,不重复

以下是您应该做的:

#headertop
{
    margin: 0 auto;
    background-image:url(http://dummyimage.com/900x100/ab24ab/0011ff.png&text=Header);
    background-repeat:no-repeat;
    background-color:#000000;
}

您不需要添加autowidth容器-只需将body元素用于背景图像,因为它将横跨整个屏幕,而不管容器的大小。

我们可以看到一些代码/实时示例吗?这不会产生所需的效果。