Linux 拨号vps windows公众号手机端

html怎么设置div居中

lewis 6年前 (2019-03-25) 阅读数 13 #程序编程
文章标签 divhtml

html设置div居中的方法:1.创建html文件;2.添加html架构代码到html文件中;3.在html架构中的body标签里面使用div标签设置一个div盒子;4.在html架构中的html标签里面添加script标签并设置居中样式;5.通过浏览器方式查看设置效果。

html设置div居中的方法:

通过设置“左右margin”值为“auto”来实现居中。

操作步骤:

1.首先创建一个html文件。

2.将html架构代码添加到html文件中。

<!DOCTYPEhtml>

<html>

<head>

<title>div居中示例</title>

</head>

<body>

</body>

</html>

3.在html架构中的body标签里面使用div标签设置一个div盒子。

<div>定宽块状元素水平居中</div>

4.在html架构中的html标签里面添加script标签并设置居中样式。

<style>

div{

border:1pxsolidred;

width:200px;/*定宽*/

margin:20pxauto;/*margin-left与margin-right设置为auto*/

}

</style>

5.最后可通过浏览器方式阅读html文件查看设置效果。

完整示例代码:

<!DOCTYPEhtml>

<html>

<head>

<title>div居中示例</title>

</head>

<style>

div{

border:1pxsolidred;

width:200px;/*定宽*/

margin:20pxauto;/*margin-left与margin-right设置为auto*/

}

</style>

<body>

<div>定宽块状元素水平居中</div>

</body>

</html>

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门