我是 CSS 初学者,想创建一个简单的盒子并将另一个盒子放在第一个盒子的中心,
尝试过这样的事情
#first {
width: 100px;
height: 100px;
background: red;
}
#first #second{
width: 50%;
height: 50%;
background: green;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>BOX-EXAMPLE</title>
</head>
<body>
<div id="first">
<div id="second"></div>
</div>
</body>
</html>
但不如预期。
最佳答案
#first {
width: 100px;
height: 100px;
background: red;
overflow: hidden;
}
#first #second{
position: relative;
width: 50%;
height: 50%;
margin: auto;
margin-top: 25%;
background: green;
}
关于html - CSS:在另一个盒子中创建一个盒子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27690404/