【问题标题】:Make class element bigger on hover在悬停时使类元素更大
【发布时间】:2017-10-12 15:20:22
【问题描述】:

我为页面上的“下一个”和“上一个”功能设置了一个类,我想做的是在悬停时使其更大(其他元素会同时移到一边)。这不是很清楚..所以例如:

我的鼠标悬停在 NEXT 按钮上,此时我想让这个按钮变大。所以这意味着它会占用更多空间,因此其他元素(背面和顶部)会移到一边。

我只是不确定我是否可以使用类而不是 id 来做到这一点?我试过放 .next:hover{width:120%} 但它没有做任何事情

这是我的代码

#pager{
width:100%;
height:50px;
margin-top:20px;
margin-bottom:20px;
margin-left:auto;
margin-right:auto;
}
 
#pagination{
margin:auto;
width:572px;
height:30px;
text-align:center;
}
 
.pagicon, .next{
display:inline;
}

 
.pagicon a, .next{
font-size:11px;
padding:5px;
margin:5px;
color:{color:Pagination};
background:{color:Pagination background};
border-radius:{text:Border radius};
}
 
.pagicon a:hover, .next:hover{
    cursor:pointer;
color:{color:Bold};
background:{color:Hover};  
}
 
.pagicon i, .next i{
color:{color:Icon};
font-size:15px;
margin:5px;
text-decoration:none;
}
 
.pagicon:hover i, .next:hover i{
color:{color:Bold};
}
<div id="pager">
 
<div id="pagination">
<span class="pagicon">
<a href="{PreviousPage}"><i class="fa fa-long-arrow-left" aria-hidden="true"></i> BACK </a>
</span>
 
<span class="pagicon">
<a href="#"><i class="fa fa-long-arrow-up" aria-hidden="true"></i> TOP </a>
</span>
 

<a class="next" href="{NextPage}"> NEXT <i class="fa fa-long-arrow-right" aria-hidden="true"></i></a>
</div>
 
</div>

(在实际网站中,按钮周围有框)

谢谢

【问题讨论】:

    标签: html css hover css-transitions


    【解决方案1】:

    我已经用 JS 做到了。看看下面。我用过onmouseoveronmouseout。您可以在悬停时更改字体大小。目前为 70px。

    function hoverFn(classnm) {
      document.getElementById(classnm).style.fontSize = "70px";
    }
    
    function nothoverFn(classnm) {
      document.getElementById(classnm).style.fontSize = "1em";
    }
    #pager {
      width: 100%;
      height: 50px;
      margin-top: 20px;
      margin-bottom: 20px;
      margin-left: auto;
      margin-right: auto;
    }
    
    #pagination {
      margin: auto;
      width: 572px;
      height: 30px;
      text-align: center;
    }
    
    .pagicon,
    .next {
      display: inline;
    }
    
    .pagicon a,
    .next {
      font-size: 11px;
      padding: 5px;
      margin: 5px;
      color: {
        color: Pagination
      }
      ;
      background: {
        color: Pagination background
      }
      ;
      border-radius: {
        text: Border radius
      }
      ;
    }
    
    .pagicon a:hover,
    .next:hover {
      cursor: pointer;
      color: {
        color: Bold
      }
      ;
      background: {
        color: Hover
      }
      ;
    }
    
    .pagicon i,
    .next i {
      color: {
        color: Icon
      }
      ;
      font-size:15px;
      margin:5px;
      text-decoration:none;
    }
    
    .pagicon:hover i,
    .next:hover i {
      color: {
        color: Bold
      }
      ;
    }
    <div id="pager">
    
      <div id="pagination">
        <span class="pagicon">
    <a href="{PreviousPage}"  id= "back" onmouseover="hoverFn('back')" onmouseout="nothoverFn('back')"><i class="fa fa-long-arrow-left" aria-hidden="true"></i> BACK </a>
    </span>
    
        <span class="pagicon">
    <a href="#" id="top" onmouseover="hoverFn('top')" onmouseout="nothoverFn('top')"><i class="fa fa-long-arrow-up" aria-hidden="true"></i> TOP </a>
    </span>
    
    
        <a class="next" id="next" href="{NextPage}" onmouseover="hoverFn('next')" onmouseout="nothoverFn('next')"> NEXT <i class="fa fa-long-arrow-right" aria-hidden="true"></i></a>
      </div>
    
    </div>

    希望对您有所帮助。如果可以,请标记为答案!

    【讨论】:

    • 谢谢你,太棒了!我真的很想深入了解代码以了解您所做的事情,但谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-21
    • 2022-01-18
    • 2017-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多