jingjingdidunhe

网址:http://www.cnblogs.com/asqq/archive/2012/04/09/2438745.html

1. 元素的定位的方法选择 :absolute 。

2. 给定元素的宽和高。

3.因为是absolute定位的方法, 用百分比的方法,借用left和top的属性,将元素的左上顶点的坐标定位到屏幕的中心。

4. 矫正图片的位置,margin-top和margin-left可以为负数时的属性作用,将margin-left和margin-top的值,分别定位元素宽和高的值的一半,并取为负数。

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8"/>                
 5         <title>Hello The World!</title>
 6         <link href="css/main.css" rel="stylesheet" type="text/css" />
 7         <style>
 8             #feeling{
 9                 background-color: #0000CD;
10                 position: absolute;
11                 width: 800px;
12                 height: 600px;
13                 top: 50%;
14                 left: 50%;
15                 margin-top: -300px;
16                 margin-left: -400px;
17             }
18         </style>
19     </head>
20     <body>
21         <id id="feeling">
22         </id>
23     </body>
24 </html>

 

分类:

技术点:

相关文章:

  • 2021-11-22
  • 2022-12-23
  • 2019-08-29
  • 2022-02-13
  • 2021-08-05
  • 2021-06-17
  • 2022-01-24
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2021-12-19
  • 2021-12-17
  • 2021-10-16
  • 2021-09-20
  • 2021-12-02
相关资源
相似解决方案