Blogger Information
Blog 11
fans 0
comment 1
visits 7829
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
box-sizing属性,常用的元素居中方式
一代宗师
Original
586 people have browsed it

box-sizing属性**

content-box :border、padding 的设置会破坏元素宽高,必须得重新计算;
实例演示

  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>box-sizing属性</title>
  7. <style type="text/css">
  8. .box {
  9. width: 200px;
  10. height: 200px;
  11. text-align: center;
  12. border: 10px solid black;
  13. padding: 15px;
  14. }
  15. </style>
  16. </style>
  17. </head>
  18. <body>
  19. <div class="box"></div>
  20. </body>
  21. </html>

border-box :border、padding 的设置不会影响元素的宽高;
实例演示

  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>box-sizing属性</title>
  7. <style type="text/css">
  8. .box {
  9. width: 200px;
  10. height: 200px;
  11. text-align: center;
  12. border: 10px solid black;
  13. padding: 15px;
  14. box-sizing: border-box;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div class="box"></div>
  20. </body>
  21. </html>

常用元素居中方式:

1.行级元素:水平居中使用:text-align:center,垂直居中:line-height:父元素的高度
2.块级元素:水平居中:margin:0 auto;

  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5. <title>常用元素居中方法</title>
  6. <style>
  7. *{
  8. font-size: 16px;
  9. box-sizing: border-box;
  10. }
  11. .box {
  12. margin: 0 auto;
  13. height: 10em;
  14. width: 10em;
  15. background-color: violet;
  16. }
  17. .title {
  18. line-height: 10em;
  19. text-align: center;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div class="box">
  25. <p class="title">我在中间</p>
  26. </div>
  27. </body>
  28. </html>
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