怎么把图片放在正中间

[复制链接]
查看11 | 回复8 | 2021-1-27 06:17:52 | 显示全部楼层 |阅读模式
Title
img{
margin:0auto;
width:100px;
height:100px;
}





怎么把图片放在正中间
分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:17:52 | 显示全部楼层


Title

img{
margin:0auto;
width:100px;
height:100px;
text-align:center;
display:block;
}





回复

使用道具 举报

千问 | 2021-1-27 06:17:52 | 显示全部楼层
引用1楼LittleMan_LC的回复:

Title

img{
margin:0auto;
width:100px;
height:100px;
text-align:center;
display:block;
}





我要图片上下左右都居中你这个没有上下居中
回复

使用道具 举报

千问 | 2021-1-27 06:17:52 | 显示全部楼层



Title
html,body{
margin:0;
margin:0;
height:100%;
}
img{
position:absolute;
left:50%;
top:50%;
margin-left:-50px;
margin-top:-50px;
width:100px;
height:100px;
}





回复

使用道具 举报

千问 | 2021-1-27 06:17:52 | 显示全部楼层


Title

img{
margin:0auto;
width:100px;
height:100px;
position:absolute;
top:50%;
left:50%;
}





回复

使用道具 举报

千问 | 2021-1-27 06:17:52 | 显示全部楼层
可以加left:0,right:0,top:0;bottom:0
回复

使用道具 举报

千问 | 2021-1-27 06:17:52 | 显示全部楼层


Title
img{
margin:0auto;
width:100px;
height:100px;
text-align:center;
}





回复

使用道具 举报

千问 | 2021-1-27 06:17:52 | 显示全部楼层
如果只要水平居中

img{
display:block;
margin:auto;
width:100px;
height:100px;
}

垂直居中

img{
margin:auto;
width:100px;
height:100px;
position:absolute;/*position:fixed*/
left:50%;
top:50%;
margin-left:-50px;
margin-top:-50px;
}

回复

使用道具 举报

千问 | 2021-1-27 06:17:52 | 显示全部楼层
方法1:display:block;margin:auto;
方法2:图片的父元素设置text-align:center
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行