CSS笔记
CSS
一、 如何让盒子水平居中
1. flex
//父元素
{
dispaly:flex;
justify-content:center;
align-item:center;
}
- flex + margin
//父元素
{
display:flex
}
//子元素
{
margin:auto
}
2. 定位
- margin + 定位
//父元素
{
position:reletive;
}
//子元素
{
positon:absolute;
top:0;
left:0;
right:0;
bottom:0;
margin:auto
}
- 定位+ transform
//父元素
{
position:reletive;
}
//子元素
{
position:absolute;
top:50%;
left:50%;
translate:(-50%,-50%)
}
二、CSS 盒子模型
盒子模型包括的内容为:margin + border + padding + content
1. W3C(标准盒子模型)
- 宽度不包括 margin、border、padding、content
- 设置 border / padding 会使盒子变大
- box-sizing :content-box
2. IE (怪异盒子模型)
- 盒子的宽度是固定的,宽度包括了 content 、border、padding
- box-sizing:border-box