CSS 日常练习----边缘对齐

记录日常 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
margin: 0;
padding: 0;
}
ul{
margin: 0;
padding: 0;
list-style: none;
}
body{
margin: 0;
}
ul{
margin: 0;
padding: 0;
list-style: none;
}
.box{
width: 200px;
height: 100px;
border: 2px solid black;
background-color: lightgreen;
margin:0 200px;
}
.out{
text-align: right;
background: red;
}
.list{
position: absolute;
margin: 10px 0 0 2px;
display: inline-block;
}
.in{
text-align: center;
width: 20px;
line-height: 20px;
margin-top: 4px;
background-color: pink;
border-radius: 50%;
}
</style>
</head>
<body>
<p>原理:out不设宽度默认是父元素width,为200px,</p>
<div class="box">
<div class="out">
<!-- 对于safari浏览器需要添加空格&nbsp;来触发右对齐,其他浏览器则不需要-->
<!--&nbsp;-->
<ul class="list">
<li class="in"></li>
<li class="in"></li>
<li class="in"></li>
</ul>
</div>
</div>
</body>
</html>
0%