css中如何将一张图片放于背景图片正中

html-css07

css中如何将一张图片放于背景图片正中,第1张

最佳答案

<html>

<head>

<title>无标题文档</title>

<style>

div

{

wdith:470px

height:80px

background:url(http://eiv.baidu.com/mc_files/20090227/20090227182703_49861100T1T396485.gif) no-repeat 0 0

padding:5px 0 5px 100px

}

img

{

width:80px

height:80px

}

</style>

</head>

<body>

<div>

<img src="http://www.baidu.com/search/zhidao/img/p2.jpg"alt="" />

</div>

</body>

</html>

你要的是下面这种效果吗?

因看不到你#imgp 这个DIV的样式,也看不到你form是否有样式。

建议通过以下两个样式进行调整:

 <style>

 #img{padding: 0px autotext-align:center} /** 解决因为DIV内边距导致的问题,让DIV内容居中 */

 #img form{margin: 0px autopadding: 0px auto}/** 解决因为form内外边距导致的问题 */

 </style>

itjob为你解答:

html:

<div class="itjob">

<img src="图片地址"/>

</div>

css:

<style>

.itjob{

width:300px

height:300px

margin:0 auto

/*下面这两行会将你div中的图片对齐,一直在中间显示,缩小或放大都会居中--远标培训*/

display:flex

justify-content:center

}

</style>