css垂直居中的几种方法

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

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

css垂直居中的几种方法

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

css垂直居中的几种方法

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

css垂直居中的几种方法

4、然后在html文件中键入如下代码:<!DOCTYPE html><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垂直居中的几种方法
  • HTML中input输入框输入内容位置设置为右边输入
  • Visual Studio怎么新建html页面
  • 怎样去除ul前面的小点?
  • 怎么修改HBuilder的颜色?
  • html怎么引用css文件
  • 热门搜索
    槐花怎么做好吃呢 头发怎么保养 家常麻婆豆腐 腊梅花怎么养 汗斑的最佳治疗方法 大便干燥怎么调理 狗吐了怎么回事 腰花怎么做好吃 怎么样减肥快 地三鲜的家常做法