手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

css垂直居中的几种方法

时间:2024-10-14 00:12:22

1、鼠标点击打开HBuilder软件,如图所示:

css垂直居中的几种方法

2、新建一个Web项目,如图所示:

css垂直居中的几种方法

3、输入web项目名CSS,然后点击完成按钮,如图所示:

css垂直居中的几种方法

4、然后在html文件中键入如下代码:<!DOCTYPE html>&盟敢势袂lt;html> <head> <meta charset="utf-8" /> <title>CSS垂直居中的几种方法?</title> </head><style type="text/css"> #one1 { display: table; background-color: red;}#frist1 { display: table-cell; vertical-align: middle;}.second{ position: absolute; top: 50%; height: 240px; margin-top: -120px; /* negative half of the height */}#three { float: left; height: 50%; margin-bottom: -120px;}#thrid { clear: both; height: 240px; position: relative;}#four { height: 100px; line-height: 100px;} </style> <body> <h4>方法一、</h4> <div id="one1"> <div id="frist1"> <div>方法一内容</div> </div> </div> <br/> <h4>方法二、</h4> <div class="second"> 方法二内容</div> <br/> <h4>方法三、</h4> <div id="three"> <div id="thrid">方法三内容</div> </div> <br/> <h4>方法四、</h4> <div id="four">方法四内容</div> </body></html>

css垂直居中的几种方法

5、然后点击运行按钮,点击运行-->浏览器运行,如图所示:

css垂直居中的几种方法

6、在浏览器中查看居中结果,有些属性是文字居中,如图所示:

css垂直居中的几种方法
© 手抄报圈