第四天
在不同的屏幕宽度下有不同的对应的css,从而有不同的显示效果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>media query</title> <style> #box{ height: 100px; background-color: #000; } @media screen and (max-width:1000px) { #box{ background-color: green; } #box h2{ color: #fff; } } @media screen and (max-width:600px) { #box{ background-color: blue; } #box h2{ color: yellow; } } </style> </head> <body> <div id="box"> <h2>box中的标题</h2> </div> </body> </html>
|
移动端自适应
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>移动端自适应</title> <style> body{ padding: 0; margin: 0; } a{ text-decoration: none; } nav{ display: flex; flex-wrap: wrap; } nav a{ width: 25%; line-height: 30px; font-size: 14px; background-color: #c00; color: #fff; text-align: center;
border-left: 1px solid #fff; border-bottom: 1px solid #fff; box-sizing: border-box; } nav a:hover{ background-color: #036; }
ul,p{ margin: 0; padding: 0; } ul{ list-style: none; } img{ border: none; display: block; } .mlist{ display: flex; padding: 0 10px; } .mlist>li{ width: 86vw; margin-left: 2px; } .mlist>li img{ width: 100%; } .mlist>li p{ line-height: 30px; text-align: center; font-size: 14px; text-overflow: ellipsis; }
ul{ padding: 0; margin: 0; list-style: none; } a{ text-decoration: none; } .zlist{ overflow: auto; } .zlist>li{ width: 25%; line-height: 30px; float: left; } .title{ margin-left: 10px; margin-top: 10px; background-color: #ccc; text-align: center; } .title a{ color: #fff; } </style> </head> <body> <nav> <a href="#">导航</a> <a href="#">导航</a> <a href="#">导航</a> <a href="#">导航</a> <a href="#">导航</a> <a href="#">导航</a> <a href="#">导航</a> <a href="#">导航</a> </nav>
<main> <ul class="mlist"> <li> <a href="#"> <img src="../Day1/2.png" alt=""> <p>这里是文字</p> </a> </li> <li> <a href="#"> <img src="../Day1/2.png" alt=""> <p>这里是文字</p> </a> </li> <li> <a href="#"> <img src="../Day1/2.png" alt=""> <p>这里是文字</p> </a> </li> </ul> </main>
<section> <ul class="zlist"> <li> <div class="title"><a href="#">自适应宽度</a></div> </li> <li> <div class="title"><a href="#">自适应宽度</a></div> </li> <li> <div class="title"><a href="#">自适应宽度</a></div> </li> <li> <div class="title"><a href="#">自适应宽度</a></div> </li> <li> <div class="title"><a href="#">自适应宽度</a></div> </li> <li> <div class="title"><a href="#">自适应宽度</a></div> </li> <li> <div class="title"><a href="#">自适应宽度</a></div> </li> <li> <div class="title"><a href="#">自适应宽度</a></div> </li> </ul> </section> </body> </html>
|
rem
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>文字大小自适应</title> <style>
html { font-size: 60px; }
@media screen and (max-width:1200px) { html { font-size: 56px; } }
@media screen and (max-width:800px) { html { font-size: 48px; } }
@media screen and (max-width:480px) { html { font-size: 28px; } }
body { padding: 0; margin: 0; min-width: 320px; }
ul, p { margin: 0; padding: 0; }
ul { list-style: none; }
img { display: block; border: none; }
.rlist { display: flex; }
.rlist>li { width: 33%; padding: 0.2rem; box-sizing: border-box; }
.rlist>li img { width: 100%; margin-top: 0.1rem; } .rlist>li p{ font-size: 0.4rem; line-height: 150%; text-align: center; color: #c00; } </style> </head>
<body> <div id="box"> rem的移动解决方案 </div>
<ul class="rlist"> <li> <a href="#"><img src="../Day1/2.png" alt=""></a> <p>这里是标题</p> </li> <li> <a href="#"><img src="../Day1/2.png" alt=""></a> <p>这里是标题</p> </li> <li> <a href="#"><img src="../Day1/2.png" alt=""></a> <p>这里是标题</p> </li> </ul> </body>
</html>
|
文字
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>文字相关属性</title> <style> #box{ width: 200px; height: 200px; background-color: #ccc; line-height: 30px;
overflow: hidden; text-overflow: ellipsis; } </style> </head> <body> <div id="box">eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee</div> </body> </html>
|
基本表单设计
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>form基本设计</title> <style> form,ul{ margin: 0; padding: 0; } ul{ list-style: none; } #form li{ overflow: auto;
border-bottom: 1px solid #ccc; width: 360px; } #form li label{ float: left; line-height: 30px; width: 70px; } .input{ width: 290px; height: 20px; margin-top: 4px; float: left;
border: none; outline: none; } .error{ width: 200px; float: left; padding-left: 10px; font-size: 12px; font-weight: bold; color: #f00; line-height: 30px; display: none; } #form li:nth-child(3){ border: none; }
</style> </head>
<body> <form action="" id="form" name="form" method="POST"> <ul> <li> <label for="user">用户名:</label> <input type="text" name="user" id="user" class="input"> <span class="error">用户名输入错误!</span> </li> <li>
<label for="pwd">密码:</label> <input type="password" name="pwd" id="pwd" class="input"> <span class="error">密码输入错误!</span> </li> <li> <input type="submit" value="提交"> </li> </ul> </form> </body>
</html>
|
图片按钮的实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>file</title> <style> #file{ width: 50px; height: 50px; position: relative; overflow: hidden; } #file input,#img{ opacity: 0; position: absolute; z-index: 3; left: 0; top: 0; width: 50px; height: 50px; } #img{ opacity: 1; z-index: 2; border-radius: 50%; background:linear-gradient(#000,#ccc); color: #fff; padding: 6px; box-sizing: border-box; text-align: center; line-height: 38px; } </style> </head> <body> <div id="file"> <input type="file" name="" id="" multiple="multiple" accept="image/jpeg,image/gif"> <div id="img">浏览</div> </div> </body> </html>
|
h5表单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>h5-form</title> </head> <body> <form action="" autocomplete="on"> <input type="email" name="" id="" placeholder="email please"> <input type="number" name="" id=""> <input type="range" name="" id="" min="1" max="100"> <input type="color" name="" id=""> <input type="date" name="" id=""> <input type="url" name="" id="" required="required"> <input type="search" name="" list="list" autofocus="autofocus"> <datalist id="list"> <option value="南昌">1</option> <option value="大连">2</option> <option value="济南">3</option> <option value="西安">4</option> </datalist> <input type="text" name="" id="" pattern="[a-z]"> <input type="submit" formaction="http://www.baidu.com"> </form> </body> </html>
|