为了账号安全,请及时绑定邮箱和手机立即绑定

哪位大神看下为啥这段代码文字显示在底部而不是在页面中部呢?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<style type="text/css">

#box2{border:red dashed 1px;width:150px}

#box1{float:left;

position:relative;

left:50%;

padding-top:50%;

}

#box2{

position:relative;

left:-50%;

}



</style>


</head>


<body>

<div id="box1">

<div id="box2">也是测试文字</div>

</div>

</body>

</html>


正在回答

1 回答

你给box1加个背景或边框 可以看见box2在最下面,

你把padding-top:50%,去掉会发现,box1和box2一样高,

因为,box1没有高度,会根据里面内容显示多高,

然后你又给box1加了上内边距,没有加下面的。。。

只能说padding-top不是这样用的


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<style type="text/css">

#box2{border:red dashed 1px;width:150px}

#box1{float:left;

position:relative;

left:50%;

padding-top:50%;

border:1px solid red;

}

#box2{

position:relative;

left:-50%;

}



</style>


</head>


<body>

<div id="box1">

<div id="box2">也是测试文字</div>

</div>

</body>

</html>


0 回复 有任何疑惑可以回复我~
#1

慕粉1440489053 提问者

非常感谢!
2017-02-24 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

哪位大神看下为啥这段代码文字显示在底部而不是在页面中部呢?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信