繁体   English   中英

如何为按钮添加悬停效果?

[英]How can i add hover effect to buttons?

谁能帮我吗。 我确实需要为创建的img按钮创建一个按钮效果。 我是否需要创建其他按钮的CSS解决方案? 我希望任何人都可以帮助我,因为我确实需要一种效果。

<html><head>  

    <title>Mobiel</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0"><!-- Bootstrap -->  

    <link href="css\bootstrap.min.css" rel="stylesheet" media="screen">  
    <link rel="stylesheet" href="css\styles_responsive.css" type="text/css" media="screen" title="no title" charset="utf-8">
    <style>  
    body {  
    padding: 50px  
    }  
    </style><!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --><!-- WARNING: Respond.js doesn't work if you view the page via file:// --><!--[if lt IE 9]>  
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>  
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>  
    <![endif]-->  


<script>
if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
  var msViewportStyle = document.createElement("style");
  msViewportStyle.appendChild(
    document.createTextNode(
      "@-ms-viewport{width:auto!important}"
    )
  );
  document.getElementsByTagName("head")[0].
    appendChild(msViewportStyle);
}
</script>

  <style>
 .navbar {
 position: left;    
 overflow: visible;   
 padding-top: 0;
 }   
 </style>
 <style type="text/css">
li{list-style-type:none;float:left;}
 a{text-align:center}
</style>

</head>  
  <body>  

 <div class="navbar navbar-fixed-top">
   <div class="navbar-inner">
     <div class="container">

<img src="img\Logo_helpen.jpg" alt="Logo"></div></div></div>
<p>
</p><p>
</p><p>
<br>
<a href="#"><img src="img\hoe-werkt-het.png" alt="Hoe werkt het?" name="Hoe werkt het?" class="img-rounded">&nbsp;&nbsp;&nbsp;&nbsp;</a>
<a href="search\index.html"><img src="img\smoelenboek.png" alt="image with rounded corners" class="img-rounded">&nbsp;&nbsp;&nbsp;&nbsp; 
<a href="alert\alert.html"><img src="img\aagje-alert.png" alt="image with rounded corners" class="img-rounded"></a></p><p>
<small>Hoe werkt&nbsp; &nbsp;&nbsp; Smoelenboek &nbsp; &nbsp;Aagje Alert <br>&nbsp; &nbsp; &nbsp; het? &nbsp;&nbsp;&nbsp;</small><br>
<img src="img\alert.jpg" alt="image with rounded corners" class="img-rounded">&nbsp;&nbsp;&nbsp;&nbsp; 
<img src="img\alert.jpg" alt="image with rounded corners" class="img-rounded">&nbsp;&nbsp;&nbsp;&nbsp;
<img src="img\alert.jpg" alt="image with rounded corners" class="img-rounded"></a></p>
<br><a href="#">
<img src="img\alert.jpg" alt="image with rounded corners" class="img-rounded">&nbsp;&nbsp;&nbsp;&nbsp;
<img src="img\alert.jpg" alt="image with rounded corners" class="img-rounded">&nbsp;&nbsp;&nbsp;&nbsp; 
<img src="img\alert.jpg" alt="image with rounded corners" class="img-rounded"></a><p><a href="#">  


<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->  
   <script src="https://code.jquery.com/jquery.js"></script>  
  <!-- Include all compiled plugins (below), or include individual files as needed -->  
    <script src="js\bootstrap.min.js"></script>     
 </a></p></body></html>

要在悬停时更改元素的CSS属性,请在CSS中使用:hover

a .img-rounded:hover {
    /* CSS here */
}

使代码更简单...将图像放入CSS:

a .img-rounded{
    background-image: url("image.png");
}

使用:hover进行悬停:

a .img-rounded:hover {
    background-image: url("hover.png");
}

好吧,这可以帮助您

<style>

a.img-rounded {
display:block;
height:10px;
background:url(image.jpg) no-repeat 0 0;
}

a.img-rounded:hover {
background:url(image.jpg) no-repeat 0 -10px;
}

</style>

尽管可以通过css onhover更改边框样式,如其他答案所示,但最好的选择是创建一个希望悬停的按钮,然后添加

onmouseover="this.src='hovereffect.jpg'" 

onmouseout="this.src='origenal.jpg'" 

悬停时要更改的按钮上的内嵌样式。

注意-最佳的悬停效果往往很简单,就像所包含的文本获得阴影或3d效果一样。

这不适用于html部分,因为每个按钮都有不同的png文件。 我只需要一个简单的悬停效果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM