Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.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中居中IMG_Css - Fatal编程技术网

在css中居中IMG

在css中居中IMG,css,Css,我想保持背景图像的中心,以便在使用不同设备时保持中心。我该怎么做? css html示例: <div class="ex"> <p>help me<p> </div> 帮帮我 首先,您必须将背景位置属性添加到类中,并将类添加到div或任何标记中,请记住,如果您希望图像始终显示在设备背面,这将使背景位于所选div的中心,您需要使用属性position:fixed .front-pg { min-height: 100v

我想保持背景图像的中心,以便在使用不同设备时保持中心。我该怎么做? css

html示例:

<div class="ex">
    <p>help me<p>
</div>

帮帮我

首先,您必须将
背景位置
属性添加到类中,并将类添加到div或任何标记中,请记住,如果您希望图像始终显示在设备背面,这将使背景位于所选div的中心,您需要使用属性
position:fixed

.front-pg {
min-height: 100vh;
background-image: url("img/IMG_20190818_145341.jpg");    
background-size: cover;   
align-items: center;
background-position: center;
 }

检查参考

移除
对齐项目:居中这里没什么关系,使用
背景位置:居中

正如一位朋友在我之前建议检查的那样,您也可以检查这些页面以了解更多信息-

  • 
    .bg{
    高度:300px;
    背景:url(https://i.imgur.com/Q15joxK.jpeg)无重复中心/盖;
    }
    
    点击snippet按钮,将代码粘贴到HTML和CSS字段中。
    .front-pg {
    min-height: 100vh;
    background-image: url("img/IMG_20190818_145341.jpg");    
    background-size: cover;   
    align-items: center;
    background-position: center;
     }