图像居中

<style>
.back{
width:500px;
height:500px;
border:2px blue solid;
text-align:center; //水平居中
}
.back img{
width:300px;
height:300px;
//margin-top:100px;
//padding-top:calc(50% - 150px); //垂直居中,直接写数值,。padding,margin均可,也可以使用relative、absolute,来定位。
}
</style>
<body>
<div class="back">
<img src="timg.jpg">
</div>
</body>
<style>
.back{
width:600px;
height:600px;
border:2px blue solid;
background:url('timg.jpg') no-repeat 0 center;
background-size:contain; /*contain把图像图像扩展至最大尺寸,以使其宽度和高度完全适应内容区域。cover 把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。背景图像的某些部分也许无法显示在背景定位区域中。*/
}
</style>
<body>
<div class="back"></div>
</body>
可能的值
描述 CSS
background-color 规定要使用的背景颜色。 1
background-position 规定背景图像的位置。 1
background-size 规定背景图片的尺寸。 3
background-repeat 规定如何重复背景图像。 1
background-origin 规定背景图片的定位区域。 3
background-clip 规定背景的绘制区域。 3
background-attachment 规定背景图像是否固定或者随着页面的其余部分滚动。 1
background-image 规定要使用的背景图像。 1
inherit 规定应该从父元素继承 background 属性的设置。 1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值