请问老师这个p标签的文字怎么实现在黄色盒子中水平居中,距离底边40px
问题描述:
请问老师这个p标签的文字怎么实现在黄色盒子中水平居中,距离底边40px
尝试过的解决方式:使用定位、display都没能实现
相关截图:

相关代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
body section {
width: 1200px;
height: 600px;
margin: 100px auto;
background-color: #f00;
position: relative;
}
body section div {
width: 400px;
height: 300px;
background-color: rgb(255, 255, 0);
position: absolute;
top: 30px;
right: 0;
}
body section div p {
text-align: center;
}
</style>
</head>
<body>
<section>
<div>
<p>测试</p>
</div>
</section>
</body>
</html>
9
收起
正在回答 回答被采纳积分+1
1回答




恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星