HTML看起来像这样HTML/CSS中心内的另一个DIV,使一个div它扩展
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Oppgave 5</title>
<style type="text/css">
</style>
</head>
<body>
<div id="animWrap">
<div id="boks"></div>
</div>
</body>
</html>
我想要做的是使DIV id为“伯克”扩大和“吃”整个DIV “animWrap”。
所以我的CSS是如下:
body{
margin: 0px;
}
#animWrap{
height: 600px;
width: 960px;
background-color: rgb(145, 75, 75);
margin: auto;
position: relative;
}
#boks{
width: 250px;
height: 175px;
top: 200px;
left: 380px;
background-color: rgb(180, 100, 100);
position: absolute;
transition: all 5s linear 0s;
}
#animWrap:hover #boks {
height: 400px;
width: 580px;
}
我注意到的是,它只是扩展到右侧,朝下方。可能是因为它没有正确居中。有没有什么方法可以从中间向每个方向扩展它,只有html和css?
删除绝对定位,并添加'保证金:0 auto'来自'#boks' – Pete