-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
503 lines (344 loc) · 38.2 KB
/
index.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
<title>杨杰 前端之路</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description">
<meta property="og:type" content="website">
<meta property="og:title" content="杨杰 前端之路">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="杨杰 前端之路">
<meta property="og:description">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="杨杰 前端之路">
<meta name="twitter:description">
<link rel="alternative" href="/atom.xml" title="杨杰 前端之路" type="application/atom+xml">
<link rel="icon" href="/img/favicon.png">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div id="container">
<div class="left-col">
<div class="overlay"></div>
<div class="intrude-less">
<header id="header" class="inner">
<a href="/" class="profilepic">
<img lazy-src="/images/me.jpg" class="js-avatar">
</a>
<hgroup>
<h1 class="header-author"><a href="/">杨杰</a></h1>
</hgroup>
<div class="switch-btn">
<div class="icon">
<div class="icon-ctn">
<div class="icon-wrap icon-house" data-idx="0">
<div class="birdhouse"></div>
<div class="birdhouse_holes"></div>
</div>
<div class="icon-wrap icon-ribbon hide" data-idx="1">
<div class="ribbon"></div>
</div>
<div class="icon-wrap icon-link hide" data-idx="2">
<div class="loopback_l"></div>
<div class="loopback_r"></div>
</div>
<div class="icon-wrap icon-me hide" data-idx="3">
<div class="user"></div>
<div class="shoulder"></div>
</div>
</div>
</div>
<div class="tips-box hide">
<div class="tips-arrow"></div>
<ul class="tips-inner">
<li>Menu</li>
<li>Tags</li>
<li>Links</li>
<li>Über</li>
</ul>
</div>
</div>
<div class="switch-area">
<div class="switch-wrap">
<section class="switch-part switch-part1">
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
<li><a href="/archives">所有文章</a></li>
</ul>
</nav>
<nav class="header-nav">
<div class="social">
<a class="github" target="_blank" href="https://github.com/melodyJie" title="github">github</a>
<a class="weibo" target="_blank" href="http://weibo.com/u/5506889097" title="weibo">weibo</a>
</div>
</nav>
</section>
<section class="switch-part switch-part2">
<div class="widget tagcloud" id="js-tagcloud">
<a href="/tags/css/" style="font-size: 10px;">css</a> <a href="/tags/markdown/" style="font-size: 10px;">markdown</a>
</div>
</section>
<section class="switch-part switch-part3">
<div id="js-friends">
<a target="_blank" class="main-nav-link switch-friends-link" href="#">only me</a>
</div>
</section>
<section class="switch-part switch-part4">
<div id="js-aboutme">我是谁,我从哪里来,我到哪里去?我就是我,是颜色不一样的吃货…</div>
</section>
</div>
</div>
</header>
</div>
</div>
<div class="mid-col">
<nav id="mobile-nav">
<div class="overlay">
<div class="slider-trigger"></div>
<h1 class="header-author js-mobile-header hide">杨杰</h1>
</div>
<div class="intrude-less">
<header id="header" class="inner">
<div class="profilepic">
<img lazy-src="/images/me.jpg" class="js-avatar">
</div>
<hgroup>
<h1 class="header-author">杨杰</h1>
</hgroup>
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
<li><a href="/archives">所有文章</a></li>
<div class="clearfix"></div>
</ul>
</nav>
<nav class="header-nav">
<div class="social">
<a class="github" target="_blank" href="https://github.com/melodyJie" title="github">github</a>
<a class="weibo" target="_blank" href="http://weibo.com/u/5506889097" title="weibo">weibo</a>
</div>
</nav>
</header>
</div>
</nav>
<div class="body-wrap">
<article id="post-markdownMethord" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/05/08/markdownMethord/" class="article-date">
<time datetime="2016-05-08T14:16:28.000Z" itemprop="datePublished">2016-05-08</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/05/08/markdownMethord/">markdownMethord</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<p>#这里是一级标题</p>
<p>###这里是三级标题</p>
<p>######这里是六级标题,就到这里了,木有七级!</p>
<p>段落前面没有缩进,看到了吧。</p>
<p> 要想使用缩进,在中文输入法中改成「全角」输入,再按两个空格</p>
<p>行尾一个回车换行,显示效果依然是是一行。<br>我说的对吧~</p>
<p>想要分成两行,需要在行尾输入两个空格。<br>我说的对吧~</p>
<p>想要开始一个新的段落,乖乖的按两下回车吧</p>
<p>我说的对吧~</p>
<p><strong>两个星号包围的是粗体</strong></p>
<p><em>一个星号包围的是斜体</em></p>
<blockquote>
<p>引用内容,多行的话,用两个空格结尾吧<br>是吧~</p>
</blockquote>
<p><code>反引号包围的是行内代码</code>,这个按键在「Tab」上边</p>
<p><code>嵌套的话,可以使用`两个双引号`嵌套在外面</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#三个反引号包围的是代码块。 </span></span><br><span class="line"><span class="comment">#会显示行号。 </span></span><br><span class="line"><span class="comment">#也有高亮显示 </span></span><br><span class="line"><span class="comment">#我上面加了python,你也可以不加。如果不能高亮,那么还是加上吧。。另外,如果你的代码块包围的是html,那你应该写html而不是python</span></span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">print</span> os.sep</span><br></pre></td></tr></table></figure>
<p>嵌套的话,可以使用六个反引号嵌套在外面。</p>
<ol>
<li>有序列表1,注意点之后的空格。</li>
<li>有序列表2.</li>
<li><p>我这里写成1,在显示时还是3,厉害不。</p>
</li>
<li><p>有序列表1<br>详细内容,注意前面有一个空格</p>
</li>
<li>有序列表2<br>详细内容</li>
</ol>
<ul>
<li>无序列表1</li>
<li>无序列表2</li>
<li>无序列表3<ul>
<li>小1,注意前面有一个空格</li>
<li>小2</li>
</ul>
</li>
</ul>
<p>超级链接:<a href="http://zipperary.com" target="_blank" rel="external">我的博客</a></p>
<p>插入图片:<img src="http://ww2.sinaimg.cn/large/5e8cb366jw1e62o63tkv3j20dh078q5a.jpg" alt="好看不"></p>
<p>另外,markdown完全兼容html,你可以用html插入这些东西,例如:</p>
<iframe height="498" width="510" src="http://player.youku.com/embed/XMjI2MjU3MDMy" frameborder="0" allowfullscreen></iframe>
<p><del>删除线</del></p>
<p>分割线用<code>---</code>,注意单独一样,上面必须是一个空行</p>
<hr>
<p>更多高级的格式,请果断插入html标签</p>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/markdown/">markdown</a></li></ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-clearfix" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/05/08/clearfix/" class="article-date">
<time datetime="2016-05-08T14:09:08.000Z" itemprop="datePublished">2016-05-08</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/05/08/clearfix/">清除浮动的八种方法</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h2 id="1-父级div定义-height"><a href="#1-父级div定义-height" class="headerlink" title="1. 父级div定义 height"></a>1. 父级div定义 height</h2><h3 id="代码如下"><a href="#代码如下" class="headerlink" title="代码如下:"></a>代码如下:</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="undefined"> </span><br><span class="line">.div1{background:#000080;border:1px solid red;/*解决代码*/height:200px;}</span><br><span class="line">.div2{background:#800080;border:1px solid red;height:100px;} </span><br><span class="line">.left{float:left;width:20%;height:200px;background:#DDD} </span><br><span class="line">.right{float:right;width:30%;height:80px;background:#DDD} </span><br><span class="line"></span><span class="tag"></<span class="name">style</span>></span></span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>></span>Left<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>></span>Right<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>></span></span><br><span class="line">div2</span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure>
<style type="text/css">.div1{background:#000080;border:1px solid red;/*解决代码*/height:200px;}.div2{background:#800080;border:1px solid red;height:100px;}.left{float:left;width:20%;height:200px;background:#DDD}.right{float:right;width:30%;height:80px;background:#DDD}</style>
<div class="div1"><div class="left">Left</div><div class="right">Right</div></div><div class="div2">div2</div>
<blockquote>
<p>原理:父级div手动定义height,就解决了父级div无法自动获取到高度的问题。 </p>
<p>优点:简单、代码少、容易掌握 </p>
<p>缺点:只适合高度固定的布局,要给出精确的高度,如果高度和父级div不一样时,会产生问题 </p>
<p>建议:不推荐使用,只建议高度固定的布局时使用</p>
</blockquote>
<p><br><br></p>
<h2 id="2-结尾处加空div标签-clear-both"><a href="#2-结尾处加空div标签-clear-both" class="headerlink" title="2. 结尾处加空div标签 clear:both"></a>2. 结尾处加空div标签 clear:both</h2><h3 id="代码如下-1"><a href="#代码如下-1" class="headerlink" title="代码如下:"></a>代码如下:</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="undefined"> </span><br><span class="line">.div1{background:#000080;border:1px solid red} </span><br><span class="line">.div2{background:#800080;border:1px solid red;height:100px;} </span><br><span class="line">.left{float:left;width:20%;height:200px;background:#DDD} </span><br><span class="line">.right{float:right;width:30%;height:80px;background:#DDD} </span><br><span class="line">/*清除浮动代码*/ </span><br><span class="line">.clearfloat{clear:both} </span><br><span class="line"></span><span class="tag"></<span class="name">style</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>></span>Left<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>></span>Right<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"clearfloat"</span>></span><span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>></span> </span><br><span class="line">div2 </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure>
<style type="text/css">.div1{background:#000080;border:1px solid red}.div2{background:#800080;border:1px solid red;height:100px;}.left{float:left;width:20%;height:200px;background:#DDD}.right{float:right;width:30%;height:80px;background:#DDD}.clearfloat{clear:both}/*清除浮动代码*/</style>
<div class="div1"><div class="left">Left</div><div class="right">Right</div><div class="clearfloat"></div></div><div class="div2">div2</div>
<blockquote>
<p>原理:添加一个空div,利用css提高的clear:both清除浮动,让父级div能自动获取到高度 </p>
<p>优点:简单、代码少、浏览器支持好、不容易出现怪问题 </p>
<p>缺点:不少初学者不理解原理;如果页面浮动布局多,就要增加很多空div,让人感觉很不好 </p>
<p>建议:不推荐使用,但此方法是以前主要使用的一种清除浮动方法 </p>
</blockquote>
<p><br><br></p>
<h2 id="3-父级div定义-伪类-after-和-zoom"><a href="#3-父级div定义-伪类-after-和-zoom" class="headerlink" title="3. 父级div定义 伪类:after 和 zoom"></a>3. 父级div定义 伪类:after 和 zoom</h2><h3 id="代码如下-2"><a href="#代码如下-2" class="headerlink" title="代码如下:"></a>代码如下:</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="undefined"> </span><br><span class="line">.div1{background:#000080;border:1px solid red;} </span><br><span class="line">.div2{background:#800080;border:1px solid red;height:100px;margin-top:10px} </span><br><span class="line">.left{float:left;width:20%;height:200px;background:#DDD} </span><br><span class="line">.right{float:right;width:30%;height:80px;background:#DDD} </span><br><span class="line">/*清除浮动代码*/ </span><br><span class="line">.clearfloat:after{display:block;clear:both;content:"";visibility:hidden;height:0} </span><br><span class="line">.clearfloat{zoom:1} </span><br><span class="line"></span><span class="tag"></<span class="name">style</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1 clearfloat"</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>></span>Left<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>></span>Right<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>></span> </span><br><span class="line">div2 </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure>
<style type="text/css">.div1{background:#000080;border:1px solid red;}.div2{background:#800080;border:1px solid red;height:100px;margin-top:10px}.left{float:left;width:20%;height:200px;background:#DDD}.right{float:right;width:30%;height:80px;background:#DDD}.clearfloat:after{display:block;clear:both;content:"";visibility:hidden;height:0}.clearfloat{zoom:1}</style>
<div class="div1 clearfloat"><div class="left">Left</div>><div class="right">Right</div></div><br><div class="div2">div2</div>
<blockquote>
<p>原理:IE8以上和非IE浏览器才支持:after,原理和方法2有点类似,zoom(IE转有属性)可解<br> ie6,ie7浮动问题 </p>
<p>优点:浏览器支持好、不容易出现怪问题(目前:大型网站都有使用,如:腾迅,网易,新浪等等) </p>
<p>缺点:代码多、不少初学者不理解原理,要两句代码结合使用才能让主流浏览器都支持。 </p>
<p>建议:推荐使用,建议定义公共类,以减少CSS代码。 </p>
</blockquote>
<p><br><br></p>
<h2 id="4-父级div定义-overflow-hidden-并定义宽度"><a href="#4-父级div定义-overflow-hidden-并定义宽度" class="headerlink" title="4. 父级div定义 overflow:hidden (并定义宽度)"></a>4. 父级div定义 overflow:hidden (并定义宽度)</h2><h3 id="代码如下-3"><a href="#代码如下-3" class="headerlink" title="代码如下:"></a>代码如下:</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="undefined"> </span><br><span class="line">.div1{background:#000080;border:1px solid red;/*解决代码*/width:98%;overflow:hidden} </span><br><span class="line">.div2{background:#800080;border:1px solid red;height:100px;width:100%} </span><br><span class="line">.left{float:left;width:20%;height:200px;background:#DDD} </span><br><span class="line">.right{float:right;width:30%;height:80px;background:#DDD} </span><br><span class="line"></span><span class="tag"></<span class="name">style</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>></span>Left<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>></span>Right<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>></span> </span><br><span class="line">div2 </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure>
<style type="text/css">.div1{background:#000080;border:1px solid red;/*解决代码*/width:98%;overflow:hidden}.div2{background:#800080;border:1px solid red;height:100px;width:100%}.left{float:left;width:20%;height:200px;background:#DDD}.right{float:right;width:30%;height:80px;background:#DDD}</style>
<div class="div1"><div class="left">Left</div><div class="right">Right</div></div><div class="div2">div2</div>
<blockquote>
<p>原理:必须定义width或zoom:1,同时不能定义height,使用overflow:hidden时,浏览器会自动检查浮动区域的高度 </p>
<p>优点:简单、代码少、浏览器支持好 </p>
<p>缺点:不能和position配合使用,因为超出的尺寸的会被隐藏。 </p>
<p>建议:只推荐没有使用position或对overflow:hidden理解比较深的朋友使用。 </p>
</blockquote>
<p><br><br></p>
<h2 id="5-父级div定义-overflow-auto"><a href="#5-父级div定义-overflow-auto" class="headerlink" title="5. 父级div定义 overflow:auto"></a>5. 父级div定义 overflow:auto</h2><h3 id="代码如下-4"><a href="#代码如下-4" class="headerlink" title="代码如下:"></a>代码如下:</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="undefined"> </span><br><span class="line">.div1{background:#000080;border:1px solid red;/*解决代码*/width:98%;overflow:auto} </span><br><span class="line">.div2{background:#800080;border:1px solid red;height:100px;width:98%} </span><br><span class="line">.left{float:left;width:20%;height:200px;background:#DDD} </span><br><span class="line">.right{float:right;width:30%;height:80px;background:#DDD} </span><br><span class="line"></span><span class="tag"></<span class="name">style</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>></span>Left<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>></span>Right<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>></span> </span><br><span class="line">div2 </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure>
<style type="text/css">.div1{background:#000080;border:1px solid red;/*解决代码*/width:98%;overflow:auto}.div2{background:#800080;border:1px solid red;height:100px;width:98%}.left{float:left;width:20%;height:200px;background:#DDD}.right{float:right;width:30%;height:80px;background:#DDD}</style>
<div class="div1"><div class="left">Left</div><div class="right">Right</div></div><div class="div2">div2</div>
<blockquote>
<p>原理:必须定义width或zoom:1,同时不能定义height,使用overflow:auto时,浏览器会自动检查浮动区域的高度 </p>
<p>优点:简单、代码少、浏览器支持好 </p>
<p>缺点:内部宽高超过父级div时,会出现滚动条。 </p>
<p>建议:不推荐使用,如果你需要出现滚动条或者确保你的代码不会出现滚动条就使用吧。 </p>
</blockquote>
<p><br><br></p>
<h2 id="6-父级div-也一起浮动"><a href="#6-父级div-也一起浮动" class="headerlink" title="6. 父级div 也一起浮动"></a>6. 父级div 也一起浮动</h2><h3 id="代码如下-5"><a href="#代码如下-5" class="headerlink" title="代码如下:"></a>代码如下:</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="undefined"> </span><br><span class="line">.div1{background:#000080;border:1px solid red;/*解决代码*/width:98%;margin-bottom:10px;float:left} </span><br><span class="line">.div2{background:#800080;border:1px solid red;height:100px;width:98%;/*解决代码*/clear:both} </span><br><span class="line">.left{float:left;width:20%;height:200px;background:#DDD} </span><br><span class="line">.right{float:right;width:30%;height:80px;background:#DDD} </span><br><span class="line"></span><span class="tag"></<span class="name">style</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>></span>Left<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>></span>Right<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>></span> </span><br><span class="line">div2 </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure>
<style type="text/css">.div1{background:#000080;border:1px solid red;/*解决代码*/width:98%;margin-bottom:10px;float:left}.div2{background:#800080;border:1px solid red;height:100px;width:98%;/*解决代码*/clear:both}.left{float:left;width:20%;height:200px;background:#DDD}.right{float:right;width:30%;height:80px;background:#DDD}</style>
<div class="div1"><div class="left">Left</div><div class="right">Right</div></div><div class="div2">div2</div>
<blockquote>
<p>原理:所有代码一起浮动,就变成了一个整体 </p>
<p>优点:没有优点 ….</p>
<p>缺点:会产生新的浮动问题。 </p>
<p>建议:不推荐使用,只作了解。 </p>
</blockquote>
<p><br><br></p>
<h2 id="7-父级div定义-display-table"><a href="#7-父级div定义-display-table" class="headerlink" title="7. 父级div定义 display:table"></a>7. 父级div定义 display:table</h2><h3 id="代码如下-6"><a href="#代码如下-6" class="headerlink" title="代码如下:"></a>代码如下:</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="undefined"> </span><br><span class="line">.div1{background:#000080;border:1px solid red;/*解决代码*/width:98%;display:table;margin-bottom:10px;} </span><br><span class="line">.div2{background:#800080;border:1px solid red;height:100px;width:98%;} </span><br><span class="line">.left{float:left;width:20%;height:200px;background:#DDD} </span><br><span class="line">.right{float:right;width:30%;height:80px;background:#DDD} </span><br><span class="line"></span><span class="tag"></<span class="name">style</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>></span>Left<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>></span>Right<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>></span> </span><br><span class="line">div2 </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure>
<style type="text/css">.div1{background:#000080;border:1px solid red;/*解决代码*/width:98%;display:table;margin-bottom:10px;}.div2{background:#800080;border:1px solid red;height:100px;width:98%;}.left{float:left;width:20%;height:200px;background:#DDD}.right{float:right;width:30%;height:80px;background:#DDD}</style>
<div class="div1"><div class="left">Left</div><div class="right">Right</div></div><div class="div2">div2</div>
<blockquote>
<p>原理:将div属性变成表格 </p>
<p>优点:没有优点 </p>
<p>缺点:会产生新的未知问题。 </p>
<p>建议:不推荐使用,只作了解。 </p>
</blockquote>
<p><br><br></p>
<h2 id="8-结尾处加-br标签-clear-both"><a href="#8-结尾处加-br标签-clear-both" class="headerlink" title="8. 结尾处加 br标签 clear:both"></a>8. 结尾处加 br标签 clear:both</h2><h3 id="代码如下-7"><a href="#代码如下-7" class="headerlink" title="代码如下:"></a>代码如下:</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="undefined"> </span><br><span class="line">.div1{background:#000080;border:1px solid red;margin-bottom:10px; zoom:1 } </span><br><span class="line">.div2{background:#800080;border:1px solid red;height:100px} </span><br><span class="line">.left{float:left;width:20%;height:200px;background:#DDD} </span><br><span class="line">.right{float:right;width:30%;height:80px;background:#DDD} </span><br><span class="line">.clearfloat{clear:both} </span><br><span class="line"></span><span class="tag"></<span class="name">style</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div1"</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"left"</span>></span>Left<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"right"</span>></span>Right<span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">br</span> <span class="attr">class</span>=<span class="string">"clearfloat"</span> /></span> </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span> </span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"div2"</span>></span> </span><br><span class="line">div2 </span><br><span class="line"><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure>
<style type="text/css">.div1{background:#000080;border:1px solid red;margin-bottom:10px; zoom:1 }.div2{background:#800080;border:1px solid red;height:100px}.left{float:left;width:20%;height:200px;background:#DDD}.right{float:right;width:30%;height:80px;background:#DDD}.clearfloat{clear:both}</style>
<div class="div1"><div class="left">Left</div><div class="right">Right</div><br class="clearfloat"></div><div class="div2">div2</div>
<blockquote>
<p>原理:父级div定义zoom:1来解决IE浮动问题,结尾处加 br标签 clear:both </p>
<p>建议:不推荐使用,只作了解。</p>
</blockquote>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/css/">css</a></li></ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</article>
</div>
<footer id="footer">
<div class="outer">
<div id="footer-info">
<div class="footer-left">
© 2016 杨杰
</div>
<div class="footer-right">
<a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
</div>
</div>
</div>
</footer>
</div>
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
<script>
var yiliaConfig = {
fancybox: true,
mathjax: true,
animate: true,
isHome: true,
isPost: false,
isArchive: false,
isTag: false,
isCategory: false,
open_in_new: false
}
</script>
<script src="http://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script>
<script src="/js/main.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true,
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
}
});
MathJax.Hub.Queue(function() {
var all = MathJax.Hub.getAllJax(), i;
for(i=0; i < all.length; i += 1) {
all[i].SourceElement().parentNode.className += ' has-jax';
}
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</div>
</body>
</html>