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

时间:2014-06-20 15:59:19

标签: jquery html css html5 twitter-bootstrap

任何人都可以帮助我。我真的需要为我创建的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>

5 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:1)

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

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

使用:hover进行悬停:

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

答案 2 :(得分:1)

这可以帮到你

<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>

答案 3 :(得分:1)

虽然可以使用css onhover更改样式,如css onhover,如其他答案所示,您最好的选择是创建另一个按钮,您希望将其悬停在上面,然后添加

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

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

在悬停时您想要更改的按钮上的内联样式。

注意 - 最好的悬停效果往往很简单,就像包含阴影或3d效果的文字一样。

答案 4 :(得分:1)

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