Blogger Information
Blog 13
fans 0
comment 0
visits 8354
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1218 box-sizing属性+常用的元素居中方式
一米互联
Original
565 people have browsed it

实例演示box-sizing属性

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>box-sizing的使用</title>
  6. <style>
  7. :root{
  8. font-size:1.25em;
  9. margin: 0;
  10. padding:0;
  11. border: 0; }
  12. .box{
  13. font-size: 1.2rem; /*24px*/
  14. width: 10em; /*240px*/
  15. height: 10em; /*240px*/
  16. border: 1px solid black;
  17. padding: 0.5em;
  18. margin: 0 0.2em;
  19. background: brown;
  20. box-sizing: border-box; /*只显示div的宽高像素,其他排除*/
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <div class="box"></div>
  26. </body>
  27. </html>


实例演示常用的元素居中方式

1.块级元素

  1. .align{
  2. width: 20em;
  3. background: rgb(158, 137, 137);
  4. padding: 5em 0;
  5. }
  6. .kuai{
  7. width: 5em;
  8. height: 5em;
  9. background: red;
  10. margin:0 auto;
  11. }
  1. <div class="align">
  2. <div class="kuai"></div>
  3. </div>


2.行内元素

  1. .align {
  2. width: 15em;
  3. height: 15em;
  4. border: 1px solid #000;
  5. text-align: center;
  6. }
  7. .align a {
  8. line-height: 15em;
  9. }
  1. <div class="align">
  2. <a href="http://www.baidu.com">百度一下</a>
  3. </div>


3.行内块元素

  1. .align {
  2. width: 20em;
  3. border: 1px solid #000;
  4. text-align: center;
  5. }
  6. .align img {
  7. padding: 5em 0;
  8. }
  1. <div class="align">
  2. <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1608456485219&di=181937a0a3cf7128b73ab65298014fc7&imgtype=0&src=http%3A%2F%2Fimg.aiimg.com%2Fuploads%2Fuserup%2F0909%2F2Z64022L38.jpg" width="100"/>
  3. </div>

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