Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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
Css 如何将图像居中?_Css - Fatal编程技术网

Css 如何将图像居中?

Css 如何将图像居中?,css,Css,我正在建立一个网站,在网站的顶部我有一个背景图片。背景图像占据了整个div,但我不希望这样。我希望图像保持其原始尺寸并水平居中。我该怎么做?您必须使用背景:url(路径到图像)无重复中心 .bg{ 背景:url(http://via.placeholder.com/350x150)无重复中心; 高度:250px; } 在容器上尝试文本对齐:居中。添加你的html,这样我们就可以知道你在做什么。因为它是背景图像,所以使用css背景属性background:url(path)no repeat

我正在建立一个网站,在网站的顶部我有一个背景图片。背景图像占据了整个div,但我不希望这样。我希望图像保持其原始尺寸并水平居中。我该怎么做?

您必须使用
背景:url(路径到图像)无重复中心

.bg{
背景:url(http://via.placeholder.com/350x150)无重复中心;
高度:250px;
}


在容器上尝试
文本对齐:居中。添加你的html,这样我们就可以知道你在做什么。因为它是背景图像,所以使用css背景属性
background:url(path)no repeat center