找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 查看内容

html怎样让div居中

作者:模板之家 2021-5-24 15:01 83人关注

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

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

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

DIV居中提供两个方法:

1、简单快捷方法就是加<center>内容</center>标签。

示例:

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

路过

雷人

握手

鲜花

鸡蛋
来自: 网络收集

全部回复(0)