当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <style type= "text/css" >
*{margin: 0;padding:0;}
div{
width:150px;
height: 100px;
position: relative;
border:1px solid #000;
}
img {
width: 50px;
height: 50px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
</style>
|
方法四:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <style type= "text/css" >
*{margin: 0;padding:0;}
div{
width:150px;
height: 100px;
position: relative;
border:1px solid #000;
}
img {
width: 50px;
height: 50px;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
</style>
|
方法五:弹性布局flex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <style type= "text/css" >
*{margin: 0;padding:0;}
div{
width:150px;
height: 100px;
border:1px solid #000;
display: flex;
justify-content: center;
align-items: center;
}
img {
width: 50px;
height: 50px;
}
</style>
|
效果都一样,希望能帮到大家!
以上就是图片 css div居中代码怎么写的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
css list-style-image属性怎么用
通过14张有趣生动的图片来了解 flexbox 的用法(值得收藏)
css grid布局是什么?grid布局的基本介绍
如何复制css代码
css怎么给表格设置边框
css border-bottom属性怎么用?
css里大于号表示什么
css grid-columns属性怎么用
使用 css 实现一个简单的骨架屏(skeleton screen)
html中图片显示方式-----img与background的区别
更多相关阅读请进入《css》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 图片 css div居中代码怎么写