<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312">
<title>填充</title>
<style?type="text/css">
#box1{
????text-align:center;
????word-wrap:break-word;
????width:100px;
????height:100px;
????padding:10px;
????border:5px?solid?white;
????margin:auto;
????background:red;
}
body{
????background:blue;
}
</style>
</head>
<body>
<div?id="box1">盒子盒子盒子盒子盒子盒子
</div>
</body>
</html>
4 回答

剛毅87
TA貢獻(xiàn)345條經(jīng)驗(yàn) 獲得超309個贊
單行文字 :line—height:100px
多行文字,你參考一下.
方法一:
#box1{ ????display:?flex; ????justify-content:?center; ????align-items:?center; }
方法二:
給文字加個標(biāo)簽,例如?p?標(biāo)簽 #box1{ ????position:relative p{ ????position:absolute; ????top:50%; ????margin-top:XXXpx; } XXX為文字高度的一半
添加回答
舉報(bào)
0/150
提交
取消