【发布时间】:2023-03-03 04:10:01
【问题描述】:
HTML 看起来像这样
<!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>
我想做的是让 id 为“boks”的 div 展开并“吃掉”整个 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从中间向各个方向展开?
【问题讨论】:
-
去掉绝对定位,从
#boks添加margin:0 auto
标签: css html hover transition