如何控制div内的div?

时间:2016-06-26 15:02:27

标签: html css css3 css-animations

将鼠标悬停在蓝色方框上;蓝色框将旋转170度,但它与父div重叠。我想旋转蓝色框而不重叠父div



.box {
  width:250px;
  height:250px;
  background:red;
}
.box_inside {
  position:absolute;
  width:250px;
  height:250px;
  background:blue;
  transition:all 0.7s linear;
}
.box_inside:hover {
  -ms-transform: rotate(170deg);
  -webkit-transform: rotate(170deg);
  transform: rotate(170deg);
}

<div class="box">
  <div class="box_inside"> </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

如果我理解正确,你会为父母寻找overflow:hidden。您还需要添加position:relative

&#13;
&#13;
.box {
  width:250px;
  height:250px;
  background:red;
  overflow:hidden;
  position:relative;
}
.box_inside {
  position:absolute;
  width:250px;
  height:250px;
  background:blue;
  transition:all 0.7s linear;
}
.box_inside:hover {
  -ms-transform: rotate(170deg);
  -webkit-transform: rotate(170deg);
  transform: rotate(170deg);
}
&#13;
<div class="box">
  <div class="box_inside"> </div>
</div>
&#13;
&#13;
&#13;