基础样式
<style>
.big {
width: 200px;
height: 200px;
border: 2px solid blue;
}
.small {
width: 50px;
height: 50px;
background-color: pink;
}
</style>
基本骨架
<div class="big outSideDiv">
<div class="small innerDiv"></div>
</div>
第一类 定位的方法+偏移
/* 方法一 */
.outSideDiv {
position: relative;
}
.innerDiv {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
/* 方法二 */
.outSideDiv {
position: relative;
}
.innerDiv {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
}
/* 方法三 */
.outSideDiv {
position: relative;
}
.innerDiv {
position: absolute;
left: 50%;
top: 50%;
margin-left: -25px;
margin-top: -25px;
}
第二类方法 css的弹性布局flex
/* 方法一 */
.outSideDiv {
display: flex;
justify-content: center;
align-items: center;
}
/* 方法二 */
.outSideDiv {
display: flex;
}
.innerDiv {
margin: auto;
}
第三类 css的grid方法;
/* 方法一 */
.outSideDiv {
display: grid;
}
.innerDiv {
justify-self: center;
align-self: center;
}
/* 方法二 */
.outSideDiv {
display: grid;
}
.innerDiv {
margin: auto;
}
第四类对齐方法,用到css的calc()方法
.innerDiv {
margin: 0 auto;
margin-top: calc(50% - 25px);
}
第五类 利用表格的属性
.outSideDiv {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.innerDiv {
display: inline-block;
}
有更好的方法,希望告知,感谢!
本文地址:https://blog.csdn.net/weixin_45695727/article/details/107326946
如对本文有疑问, 点击进行留言回复!!
清除新版Google Chrome浏览器中表单控件(input,button...)默认的黑色边框
荐 20200714——git/mac配置/项目运行步骤/一些报错
antd 菜单组件 使用时报错:Cannot read property ‘isRootMenu‘ of undefined
CSS|div的style=“background-image: url(img/a.bmp)图片显示不出来
硬件仪表盘账号建立指导(一) --WHQL认证测试结果提交账号(一)
cookie的规范Cookie的不可跨域名性或Cookie与域名的关系
网友评论