Blogger Information
Blog 18
fans 0
comment 0
visits 7738
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
盒模型,媒体查询,em,rem用法
只如初见
Original
343 people have browsed it

盒模型

html代码

  1. <div class="box"></div>

css代码

  1. /* border:边框
  2. padding:填充
  3. margin:外边距 */
  4. .box {
  5. width: 200px;
  6. height: 200px;
  7. border: 10px solid red;
  8. padding: 20px;
  9. margin: 20px;
  10. background-color: cadetblue;
  11. /* 实现盒子固定宽和高,不受border,padding的值影响 */
  12. box-sizing: border-box;
  13. }

效果图

媒体查询

html代码

  1. <div class="btn">提交按钮</div>

css代码

  1. /*
  2. 设置根元素大小,这里相当于设置了1rem = 10px
  3. 后面元素设置的尺寸大小,都是相对于这个基准尺寸来计算
  4. */
  5. html {
  6. font-size: 10px;
  7. }
  8. .btn {
  9. width: 20rem;
  10. height: 4rem;
  11. background: #ccc;
  12. font-size: 1.6rem;
  13. color: #333;
  14. text-align: center;
  15. line-height: 4rem;
  16. }
  17. /* 媒介查询,判断当前屏幕可视尺寸,调用对应的css代码 */
  18. @media (max-width: 320px) {
  19. html {
  20. font-size: 12px;
  21. }
  22. }
  23. @media (min-width: 321px) and (max-width: 500px) {
  24. html {
  25. font-size: 14px;
  26. }
  27. }
  28. @medi (min-width:501px) {
  29. html {
  30. font-sizt: 16px;
  31. }
  32. }

em,rem用法

html代码

  1. <div class="test"><span>em,rem用法</span></div>

css代码

  1. /* 设置根元素字号 1rem = 10px */
  2. html {
  3. font-size: 10px;
  4. }
  5. .test {
  6. font-size: 24px;
  7. }
  8. .test span {
  9. /* em会被父元素重新定义,1em = 24px */
  10. /* 这里相当于是48px了 */
  11. font-size: 2em;
  12. }
  13. .test span {
  14. /* rem不受父元素影响,只相当于根元素设置的值改变 */
  15. font-size: 2rem;
  16. }
  17. /* em和rem的区别
  18. em:会随着父元素的变化而变化,可变性太大,不好控制;
  19. rem:只相对于根元素html的值而变化,容易控制; */
Correcting teacher:PHPzPHPz

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!