html - 在悬停 CSS 上调整 Div 大小

标签 html css

我有两个与 iframe 并排的 div。当我将鼠标悬停在左侧的 div 上时,我希望右侧的 iframe 调整为 50% 宽度。左边的 div 将被调整为 50%。我更喜欢纯 CSS 方法。

.answer6{
    float:left;
    width: 100%;
}

.mpi-options-all2 {
  float: left;
  width: 100%;
  bottom: 75px;
  right: 75px;
  padding: 10px;
  background-color: black;
  color: white;  
    opacity:0.8;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
    filter: alpha(opacity=80);
    font-weight: bold;
    text-align: left;
    padding: 10px;
    position: absolute;
    right: -100%;
	text-align: center;
    top: 0px;
    height: 505px;
    z-index: 2;
    -webkit-transition: right 0.5s ease-in-out;
    -moz-transition: right 0.5s ease-in-out;
    -o-transition: right 0.5s ease-in-out;
    -ms-transition: right 0.5s ease-in-out;
    transition: right 0.5s ease-in-out;
}

.left-right{
    padding: 0px;
    margin: 0px auto;
    height: 525px;
    position: relative;
    overflow: hidden;
}

.left-right:hover .mpi-options-all2{
    right: 0;
}
<div class="answer6">
  <iframe src="https://wikipedia.org/wiki/Main_Page" width="75%" height="500" align="right"></iframe>
  <div class ="left-right">
    <div class="mpi-options-all2">
    <h2><center>Description:</center></h2>
    </div>
  </div>    
</div>

最佳答案

根据我对问题的理解,这里给出一个解决方案,看看是否正确。

<div class="answer6">
      <div class ="left-right">
        <div class="mpi-options-all2">
        <h2><center>Description:</center></h2>
        </div>
      </div>
      <iframe src="https://wikipedia.org/wiki/Main_Page" height="500" align="right"></iframe>      
    </div>

.answer6{
    width: 100%;
}
.mpi-options-all2 h2{
  display: none;
}

.mpi-options-all2 {
  width: 100%;
  bottom: 75px;
  /*right: 75px;*/
  padding: 10px;
  background-color: black;
  color: white;  
    opacity:0.8;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
    filter: alpha(opacity=80);
    font-weight: bold;
    text-align: left;
    padding: 10px;
    /*position: absolute;*/
    /*right: -100%;*/
    text-align: center;
    top: 0px;
    height: 505px;
    /*z-index: 2;*/
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -o-transition: all 0.5s ease-in-out;
    -ms-transition: all 0.5s ease-in-out;
    transition: all 0.5s ease-in-out;
}

.left-right{
    padding: 0px;
    margin: 0px auto;
    height: 525px;
    position: relative;
    overflow: hidden;
    float: left;
    width: 2%;
  -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -o-transition: all 0.5s ease-in-out;
    -ms-transition: all 0.5s ease-in-out;
    transition: all 0.5s ease-in-out;
}

iframe{
  margin:0;
  width: 97.7%;
  -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -o-transition: all 0.5s ease-in-out;
    -ms-transition: all 0.5s ease-in-out;
    transition: all 0.5s ease-in-out;
  float:right;
}
.left-right:hover .mpi-options-all2 h2{
  display: block;
}

.left-right:hover{
    width: 49.7%;
}

.left-right:hover ~ iframe{
    width: 50%;
}

https://codepen.io/anon/pen/ROEogj

关于html - 在悬停 CSS 上调整 Div 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55854247/

相关文章:

html - Chrome : unable to get :focus CSS applied on anchors

javascript - Flex 布局 - 单元格在 chrome 中部分折叠

javascript - SVG 动画在调整大小后非常滞后(专家)?

html - CSS3 图标 : inserted content isn't placed consistently

html - CSS 拉伸(stretch)内容容器高度如果为空则溢出如果太大

html - 如何在 HTML/CSS 中将文本置于方框的中心?

javascript - 站点地图树缩进可视化

css - css 样式表层次结构的重要性

javascript - 在 Bootstrap 中水平制作三个 div 的全宽和高度

css - 单击表格行中的特定链接