新聞動態

                                                                                  位置:首頁 新聞動態 建站學堂

                                                                                  襄陽網站建設告訴你-用CSS如何實現響應式布局

                                                                                  新聞動態
                                                                                  2019年12月05日 閱讀:2766次

                                                                                  第一: 直接在CSS文件中使用

                                                                                  @media 類型 and (條件1 最小) and (條件二 最大)

                                                                                  {

                                                                                  css樣式

                                                                                  }

                                                                                  第二:使用@import導入

                                                                                  @import url("css/moxie.css") all and (max-width:980px);

                                                                                   

                                                                                  第三,也是最常用的:使用link連接,media屬性用于設置查詢方式

                                                                                  我們只需用到max-width這個屬性,定義輸出設備中的頁面可見區域寬度樣式即可。



                                                                                  1. <html>

                                                                                  2. <head>

                                                                                  3. <meta charset="UTF-8">

                                                                                  4. <title>響應式布局title>

                                                                                  5. <meta name="viewport"content="width=device-width,initial-scale=1.0,maximum-scale=1,user-scalable=no" />

                                                                                  6. <meta name="format-detection" content="telephone=no,email=no"/>

                                                                                  7. <link rel="stylesheet" type="text/css" href="css/mo2.css"/>

                                                                                  8. head>

                                                                                  9. <body>

                                                                                  10. <div>

                                                                                  11. <header id="head">

                                                                                  12. <ul>

                                                                                  13. <li>header1li>

                                                                                  14. <li>header2li>

                                                                                  15. <li>header2li>

                                                                                  16. <li>header2li>

                                                                                  17. <li>header2li>

                                                                                  18. ul>

                                                                                  19. <div>icondiv>

                                                                                  20. header>

                                                                                  21. <section id="main">

                                                                                  22. <div class="left">

                                                                                  23. left

                                                                                  24. div>

                                                                                  25. <div class="center">

                                                                                  26. center

                                                                                  27. div>

                                                                                  28. <div class="right">

                                                                                  29. right

                                                                                  30. div>

                                                                                  31. section>

                                                                                  32. <footer id="foot">

                                                                                  33. footer

                                                                                  34. footer>

                                                                                  35. div>

                                                                                  36. body>

                                                                                  37. html>

                                                                                  這是CSS樣式


                                                                                  1. *{

                                                                                  2.     margin: 0px;

                                                                                  3.     padding: 0px;

                                                                                  4.     font-family: "微軟雅黑";

                                                                                  5. }

                                                                                  6. #head,

                                                                                  7. #foot,

                                                                                  8. #main

                                                                                  9. {

                                                                                  10.     height: 100px;

                                                                                  11.     width: 1200px;

                                                                                  12.     /*width: 85%;*/

                                                                                  13.     background-color: goldenrod;

                                                                                  14.     text-align: center;

                                                                                  15.     font-size: 48px;

                                                                                  16.     line-height: 100px;

                                                                                  17.     margin: 0 auto;

                                                                                  18. }

                                                                                  19. #head div{

                                                                                  20.     display: none;

                                                                                  21.     font-size: 20px;

                                                                                  22.     height: 30px;

                                                                                  23.     width: 100px;

                                                                                  24.     background-color: green;

                                                                                  25.     float: right;

                                                                                  26.     line-height: 30px;

                                                                                  27.     margin-top: 35px;

                                                                                  28. }

                                                                                  29. #head ul{

                                                                                  30.     width: 80%;

                                                                                  31. }

                                                                                  32. #head ul li{

                                                                                  33.     width: 20%;

                                                                                  34.     float: left;

                                                                                  35.     text-align: center;

                                                                                  36.     list-style: none;font-size: 20px;

                                                                                  37. }

                                                                                  38. #main{

                                                                                  39.     height: auto;

                                                                                  40.     margin: 10px auto;

                                                                                  41.     overflow: hidden;

                                                                                  42. }

                                                                                  43. .left,

                                                                                  44. .center,

                                                                                  45. .right{

                                                                                  46.     height: 600px;

                                                                                  47.     line-height: 600px;

                                                                                  48.     float: left;

                                                                                  49.     width: 20%;

                                                                                  50.     background-color: red

                                                                                  51. }

                                                                                  52. .center{

                                                                                  53.     width: 60%;

                                                                                  54.     border-left: 10px solid #FFF;

                                                                                  55.     border-right: 10px solid #FFF;

                                                                                  56.     box-sizing: border-box;

                                                                                  57. }

                                                                                  58. @media only screen and (max-width: 1200px) {

                                                                                  59.     #head,

                                                                                  60.     #foot,

                                                                                  61.     #main{

                                                                                  62.     width: 100%;

                                                                                  63.     }

                                                                                  64. }

                                                                                  65. @media only screen and (max-width: 980px) {

                                                                                  66.     .right{

                                                                                  67.         display: none;

                                                                                  68.     }

                                                                                  69.     .left{

                                                                                  70.         width: 30%;

                                                                                  71.     }

                                                                                  72.     .center{

                                                                                  73.         width: 70%;

                                                                                  74.         border-right: hidden;

                                                                                  75.     }

                                                                                  76. }

                                                                                  77. @media only screen and (max-width: 640px) {

                                                                                  78.     .left,

                                                                                  79.     .center,

                                                                                  80.     .right{

                                                                                  81.         width:

                                                                                    上一篇

                                                                                    下一篇

                                                                                  亚洲中文字幕在线19页_99久久国产精品免费热7788_欧美专区日韩专区综合专区_小泽玛利亚一区_gogo999亚洲肉体艺术