Blogger Information
Blog 10
fans 0
comment 0
visits 7419
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
盒模型居中及水平垂直
 有料!
Original
770 people have browsed it

6.盒模型居中及水平居中

1.常见盒模型元素

属性 注释
box-sizing:border-box 不计算 pading
background-clip:content-box 将 padding 裁剪出来
overflow: hidden 超出部分隐藏
overflow: auto 使用滚动条查看被隐藏的内容
height: auto 默认高度由内容撑开
min-height 最小高度当内容超过最小高度时会自动伸展
max-height 最大高度,一般配合 overflow:hidden 使用
text-align: center 规定元素中的文本的水平对齐方式
line-height 适合文字垂直居中
margin:auto 块级元素居中
position: relative 块级元素水平垂直居中,父级声明,二者缺一不可
position: absolute 块级元素水平垂直居中,当前元素声明,二者缺一不可

2.实现 padding 内容区可见及计算到元素内

  1. padding: 2em;
  2. /* 裁剪padding内容可见 */
  3. background-clip: content-box;
  4. /* 将 padding计算到元素大小内*/
  5. box-sizing: border-box;

3.盒模型水平及垂直集中

  1. <div class="box">
  2. <div></div>
  3. </div>
  1. /* \
  2. 1.块级元素水平垂直居中,父级声明position:relative;
  3. 2.然后再需要垂直居中的块级元素中添加
  4. position: absolute;生成绝对定位的元素,相对定位元素以外的第一个父元素进行定位
  5. top: 0;
  6. left: 0;
  7. right: 0;
  8. bottom: 0;
  9. margin: auto;
  10. 以上缺一不可 */
  11. .box {
  12. width: 15em;
  13. height: 15em;
  14. border: 1px solid black;
  15. background-color: blue;
  16. position: relative;
  17. }
  18. .box > div {
  19. width: 5em;
  20. height: 5em;
  21. background-color: yellow;
  22. position: absolute;
  23. top: 0;
  24. left: 0;
  25. right: 0;
  26. bottom: 0;
  27. margin: auto;
  28. }
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!