更多信息可以查看我的github仓库
MDN 定位 https://developer.mozilla.org/zh-CN/docs/Learn/CSS/CSS_layout/%E5%AE%9A%E4%BD%8D
MDN 定位实战 https://developer.mozilla.org/zh-CN/docs/Learn/CSS/CSS_layout/Practical_positioning_examples
MDN Flexbox https://developer.mozilla.org/zh-CN/docs/Learn/CSS/CSS_layout/Flexbox
布局
这个基础需要恶补
圣杯布局
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 body { margin: 0; padding: 0; } .header, .footer { background: red; padding: 20px 0; } .container { padding-left: 200px; padding-right: 200px; /* min-width: 600px; */ } .content, .left, .right { height: 200px; float : left; position: relative; } .content { width: 100%; background: gold; } .left { width: 200px; height: 200px; background: margin-left: -100%; right: 200px; } .right { width: 200px; height: 200px; background: margin-right: -200px; } .footer { clear: both; } * html .left { left: 200px; } <div class="header" > header </div> <div class="container" > <div class="content" >Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati iusto cumque quibusdam quis qui sit quisquam iure repellat perferendis. Tempora accusantium dignissimos, magnam est placeat enim dicta dolores nam distinctio!</div> <div class="left" ></div> <div class="right" ></div> </div> <div class="footer" > footer </div>
双飞翼布局
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 .left, .main, .right { float : left; min-height: 200px; } .left { background: gray; width: 200px; margin-left: -100%; } .main { background: rgb(252, 102, 102); width: 100%; } .right { background: width: 200px; margin-left: -200px; } .content { margin: 0 200px; overflow: hidden; } <div class="container" > <div class="main" > <div class="content" >Lorem ipsum dolor sit amet consectetur adipisicing elit. Culpa quos labore, ad officiis animi libero ipsam dolorum explicabo placeat facere fuga ex suscipit porro nesciunt quod mollitia corrupti voluptatem a?</div> </div> <div class="left" >left</div> <div class="right" >right</div> </div>
圣杯布局和双飞翼布局的作用和区别
http://www.cnblogs.com/woodk/p/5147085.html
http://www.cnblogs.com/imwtr/p/4441741.html
flex 布局
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 .container { -webkit-display:flex; display: flex; min-height: 200px; } .left { order: -1; background: red; flex-basis: 200px; } .main { background: forestgreen; flex-grow: 1; } .right{ background: gold; flex-basis: 300px; } <div class="container" > <div class="main" >Lorem ipsum dolor sit amet consectetur adipisicing elit. Eaque quae, veritatis dignissimos laborum debitis id accusantium dolore inventore odit sed! Sunt officiis temporibus esse eum ab fuga ad sequi officia?</div> <div class="left" >left</div> <div class="right" >right</div> </div>
绝对定位布局
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 .container { position: relative; } .main, .right, .left { top: 0; height: 130px; } .main { background: gray; margin: 0 300px 0 200px; } .right { position: absolute; width: 300px; right: 0; background: red; } .left { width: 200px; position: absolute; left: 0; background: green; } <div class="container" > <div class="main" >man</div> <div class="left" >left</div> <div class="right" >right</div> </div>
实现布局还原
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 body{ margin: 0; padding: 0; } * { box-sizing: border-box; } .fl{ float : left; } .ri { float : right; } .header{ width: 100%; min-width: 960px; height: 100px; background: } .header-content{ width: 960px; height: 100%; margin: 0 auto; } .header-content .logo{ width: 100px; height: 100%; } .header-content .logo h1 { margin: 0; padding: 0; font-size: 40px; color: line-height: 100px; text-align: center; } .header-content .about a{ display: inline-block; padding: 0 4px; color: font-size: 16px; line-height: 100px; } .banner{ width: 100%; height: 400px; background: rgb(77, 206, 77); position: relative; } .list{ position: absolute; bottom: 10px; right: 10%; -webkit-display: flex; display: flex; } .list span { display: block; width: 30px; height: 40px; line-height: 40px; background: rgba(238, 238, 238, 0.7); border: 1px solid float : left; text-align: center; align-self: flex-end; margin: 0 2px; } /* .list span:hover{ height: 50px; line-height: 60px; } */ .list span.active{ height: 50px; line-height: 60px; } .nav{ width: 100%; height: 80px; background: border-bottom: 1px solid } .nav-content { width: 960px; height: 100%; margin: 0 auto; } .nav-content a{ display: block; float : left; width: 140px; height: 50px; line-height: 50PX; text-align: center; text-decoration: none; color: border-left: 1px solid border-top: 1px solid border-right: 1px solid border-bottom: 1px solid background: border-radius: 20px 20px 0 0; margin-top: 30px; } .nav-content a.active{ background: border-bottom: 1px solid } .main{ width: 960px; overflow: hidden; margin: 10px auto 0; } .main .row{ -webkit-display: flex; display: flex; } .main .row .row-content { flex: 1; height: 200px; text-align: center; border: 1px solid /* padding: 80px; */ margin: 4px; align-items: center; justify-content: center; -webkit-display: flex; display: flex; } .footer{ width: 100%; height: 100px; background: text-align: center; line-height: 100px; font-size: 16px; color: } <div class="header" > <div class="header-content" > <div class="logo fl" > <h1>logo</h1> </div> <div class="about ri" > <a href="#" >Github</a> <a href="#" >Register</a> <a href="#" >Login</a> </div> </div> </div> <div class="banner" > <div class="list" > <span>1</span> <span class="active" >2</span> <span>3</span> <span>4</span> </div> </div> <div class="nav" > <div class="nav-content" > <a href="#" class="active" >HOME</a> <a href="#" >PROFLE</a> <a href="#" >ABOUT</a> </div> </div> <div class="main" > <div class="row" > <div class="row-content" >content</div> <div class="row-content" >content</div> <div class="row-content" >content</div> </div> <div class="row" > <div class="row-content" >content</div> <div class="row-content" >content</div> <div class="row-content" >content</div> <div class="row-content" >content</div> </div> <div class="row" > <div class="row-content" >content</div> <div class="row-content" >content</div> <div class="row-content" >content</div> </div> </div> <div class="footer" > <p>© 2018 ife.baidu.com</p> </div>
预览地址