7 回答
TA贡献1829条经验 获得超9个赞
#father{
display: flex;
align-items: center;
justify-content: center;
}
或者:
#father {
display: -webkit-box;
-webkit-box-align: center;
-webkit-box-pack : center;
}
TA贡献1802条经验 获得超4个赞
div{
position:fixed;
left: 50%;
top: 50%;
margin-left: -20%;
margin-top: -150px;
width: 40%;
height: 300px;
background: yellowgreen;
}
不定高度用JS或者CSS3.
TA贡献1942条经验 获得超3个赞
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
}
.out {
width: 200px;
height: 200px;
background: green;
position: relative;
}
.in {
width: 40%;
height: 40%;
background: red;
position: absolute;
/*(100%-40%)/2 */
top: 30%;
left: 30%;
}
</style>
</head>
<body>
<div class="out">
<div class="in"></div>
</div>
</body>
</html>
添加回答
举报