|
发表于 2017-4-17 21:02:58
|
显示全部楼层
交作业
- <html lang="en">
- <!DOCTYPE html>
- <head>
- <meta charset="UTF-8">
- <title>center</title>
- <style type="text/css">
- html,body{
- height: 100%;
- width: 100%;
- color: red;
- }
- body{
- background: url("background.jpg")center center;/*想把文字放到页面中间,必须通过设置水平、竖直两个方向都是“居中”*/
- background-size: cover; /*cover:把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。背景图像的某些部分也许无法显示在背景定位区域中。*/
- margin: 0; /*初始化内外边距*/
- padding: 0;
- position: relative; /*相对定位*/
- }
- #container0{
- width: 100%;
- text-align: center; /*文字水平居中*/
- position: absolute;
- }
- #container1{
- width: inherit; /*inherit 继承父类的属性*/
- text-align: center;
- position: absolute;
- top:50%;
- transform:translateY(-50%); /*transform:该属性允许我们对元素进行旋转、缩放、移动或倾斜。translateY(-50%):沿Y轴整体上移一半*/
- }
- #container2{
- width: 100%;
- text-align: center;
- position: absolute;
- bottom: 0;
- transform:translateY(-50%);
- /*bottom 属性规定元素的底部边缘。该属性定义了定位元素下外边距边界与其包含块下边界之间的偏移。
- 与之对应的top属性规定元素的顶部边缘。该属性定义了一个定位元素的上外边距边界与其包含块上边界之间的偏移。*/
- }
- </style>
- </head>
- <body>
- <div id="container0">
- <h1>我爱鱼C</h1>
- </div>
- <div id="container1">
- <p>让编程改变世界!<br/>Change the world by program!</p>
- </div>
- <div id="container2">
- <a href="http://www.fishc.com/" style="color: blue">传送门</a><br/>
- <a href="http://bbs.fishc.com/forum.php?mod=collection&action=view&ctid=539" style="color: blue">HTML5-庖丁解牛</a>
- </div>
- </body>
- </html>
复制代码 |
-
|