12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- .box1 div{
- width: 100px;
- height: 100px;
- background-color: blue;
- color: white;
- font-size: 30px;
- font-weight: bolder;
- margin:10px;
- text-align: center;
- /* line-height 值控制行元素的行高 行元素默认在他所在这一行中垂直居中 */
- line-height: 100px;
- float: left;
- }
- .box2 .div2{
- width: 100px;
- height: 100px;
- background-color: red;
- margin: 10px;
- color: white;
- font-size: 30px;
- font-weight: bolder;
- text-align: center;
- line-height: 100px;
- float: right;
- }
- .box3 .div3{
- width: 100px;
- height: 100px;
- background-color: green;
- margin: 10px;
- color: white;
- font-size: 30px;
- font-weight: bolder;
- text-align: center;
- line-height: 100px;
- }
- .box1,.box2,.box3{
- border: 3px solid black;
- height: 150px;
- }
- .box3 .left{
- float: left;
- /* background-color: rgba(0,255,0,0.2); */
- /* margin-top: 100px; */
- }
- .box3 .center{
- color: black;
- /* margin-left: 100px; */
- margin:10px auto;
- }
-
- .right{
- float: right;
- }
- </style>
- </head>
- <body>
- <!-- 浮动元素会脱离文档流 释放之前占用的位置 会覆盖其他元素 -->
- <div class="box1">
- <div class="div1">
- <span>1</span>
- </div>
- <div class="div1">2</div>
- <div class="div1">3</div>
- </div>
- <div class="box2">
- <div class="div2">1</div>
- <div class="div2">2</div>
- <div class="div2">3</div>
- </div>
- <div class="box3">
- <div class="div3 left">左</div>
- <!-- <div class="div3 center">中</div> -->
- <div class="div3 right">右</div>
- <div class="div3 center"> 中 </div>
- </div>
- </body>
- </html>
|