HTML中的DIV怎么居中,求,急!!!请直接修改代码

2025-03-24 00:37:38
推荐回答(5个)
回答1:

DIV居中提供两个方法:

1、简单快捷方法就是加

内容
标签。

示例:




center居中




我要居中啦



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

示例:



margin居中

.d1{
border:1px solid red;
width:200px;
height:200px;
text-align:center;
line-height:40px;
margin:0 auto;
}




我是div,我居中啦...


回答2:

#nav {
margin-top: 0px;
margin-bottom: 0px;
background-color: #000000;
width: 725px;
height: 50px;
margin-right: auto;
margin-left: auto;
}

回答3:

回答4:

nav必须得用position:fixed;吗,把它去掉就好了

回答5:

是nav这个div居中吗
需要div固定,用到position: fixed。
#nav {
background-color: #000000;
width: 725px;
height: 50px;
position: fixed;
top: 0px;
left: 50%;
margin-left: -362px;
}
不需要div固定,去掉position: fixed
#nav {
background-color: #000000;
width: 725px;
height: 50px;
margin:0 auto;
}

相关问答