forked from fanspaceshow/CodeTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavoidTextAround.html
60 lines (52 loc) · 1.74 KB
/
avoidTextAround.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
<!DOCTYPE html>
<html>
<head>
<!--
本代码来自 http://segmentfault.com/a/1190000003827247
如果仅对.avatar左浮,后面的comment不做处理,那么就会出现文字环绕的现象
解决方法:
1. 为comment添加一个左边距 .comment
2. 为comment添加overflow:hidden .comment1
-->
<meta charset="utf-8">
<title>防止文字环绕</title>
<style type="text/css">
.container {
margin: 20px;
border: 1px solid #212121;
width: 300px;
background-color: #009688;
overflow: hidden;
}
.avatar {
width: 70px;
height: 70px;
float: left;
margin: 10px;
background-color: #ffc107;
}
.comment {
/* 方法一 */
margin-left: 90px;
}
.comment1{
/* 方法二 */
overflow: hidden;
}
</style>
</head>
<body>
<div class="container">
<div class="avatar"></div>
<div class="comment">
<p>In a block formatting context, each box's left outer edge touches the left edge of the containing block. This is true even in the presence of floats, unless the box establishes a new block formatting context (in which case the box itself may become narrower due to the floats).</p>
</div>
</div>
<div class="container">
<div class="avatar"></div>
<div class="comment1">
<p>In a block formatting context, each box's left outer edge touches the left edge of the containing block. This is true even in the presence of floats, unless the box establishes a new block formatting context (in which case the box itself may become narrower due to the floats).</p>
</div>
</div>
</body>
</html>