Linux 拨号vps windows公众号手机端

css如何设置div居中

lewis 6年前 (2019-03-30) 阅读数 14 #程序编程
文章标签 cssdiv

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


具体操作步骤:

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标签里面添加style标签并设置css居中样式。

<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>


版权声明

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

发表评论:

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

热门