首页  >  文章  >  web前端  >  html怎样让div居中

html怎样让div居中

藏色散人
藏色散人原创
2021-05-24 11:02:3337654浏览

html让div居中的方法:1、通过加“bacbf9e1ad7f40415ce1670e31edfee3内容adca8a5fa06ffeafb062c2e3f274b930”标签让div居中;2、在div中加入“margin:0 auto属性;”自动调节居中。

html怎样让div居中

本文操作环境:windows7系统、HTML5&&CSS3版、Dell G3电脑。

DIV居中提供两个方法:

1、简单快捷方法就是加bacbf9e1ad7f40415ce1670e31edfee3内容adca8a5fa06ffeafb062c2e3f274b930标签。

示例:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>center居中</title>
</head>
 
<body>
<center>
<div>我要居中啦</div>
</center>
</body>
</html>

2、div中加入margin:0 auto属性;自动调节居中。

示例2:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>margin居中</title>
<style type="text/css">
.d1{
border:1px solid red;
width:200px;
height:200px;
text-align:center;
line-height:40px;
margin:0 auto;
}
</style>
</head>
<body>
<div class="d1">
我是div,我居中啦...
</div>
</body>
</html>

推荐教程:html视频教程css视频教程

以上是html怎样让div居中的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn