[英]How can I “highlight” this CSS button when is clicked using CSS3 or JavaScript?
into an HTML page I have 2 buttons implemented by something like this: 进入HTML页面,我有2个按钮,它们是由类似以下内容的实现:
<!-- Bottone relativo ai progetti WIFI: -->
<a title="WIFI" href="javascript: void(0)" id="showWifi_${item.index}" class="showWifi">
<div class="news_box news_box_01 hvr-underline-from-center " style="margin-right: 50px;"></div>
</a>
<!-- Bottone relativo ai progetti PNSD: -->
<a title="PNSDe" href="javascript: void(0)" id="showPnsd_${item.index}" class="showPnsd">
<div class="news_box news_box_02 hvr-underline-from-center "></div>
</a>
And this is the related CSS that show a background immage to the div implementing the button: 这是相关的CSS,显示了实现该按钮的div的背景图像:
.news_box_01 {
background: rgba(0, 0, 0, 0) url("../../img/icons/projects/wifi_big_transparent_2.png") repeat scroll 0 0;
}
.news_box_02 {
background: rgba(0, 0, 0, 0) url("../../img/icons/projects/PNSD.png") repeat scroll 0 0;
}
Ok, now my problem is that I have to highlight the selected button when the user click on it. 好的,现在我的问题是,当用户单击所选按钮时,我必须突出显示该按钮。
I know that I can use the :active selector to select a clicked link. 我知道我可以使用:active选择器来选择单击的链接。 The problem is that I don't know how can I use CSS to "hightlight" (or implement some other CSS 3 effect) on the backround immage when the link is clicked
问题是我不知道如何在单击链接时使用CSS来突出显示背景图像(或实现其他CSS 3效果)
Do you have some idea? 你有什么主意吗
If i understood correctely, you want to apply changes for after a click. 如果我正确地理解,您想在单击后应用更改。
$(".showWifi").on("mousedown", function() {
//fires when the mouse is press down
//using "click" instead of "mousedown" means the mousebutton
//must be pressed down then up before the function fires.
$(this).addClass("highLightButton");
})
don't hesitate to ask for further explanation or help 请随时寻求进一步的解释或帮助
use :active for anchor elements 使用:active用于锚元素
a:active {/*styles here*/}
http://codepen.io/anon/pen/JYYGLG http://codepen.io/anon/pen/JYYGLG
Use :active
selector in your css: 在CSS中使用
:active
选择器:
a:active .news-box{
/*
Some magic code to make a nice background!
*/
}
so whenever your a
is active, the css above will be applied to the .news-box
child of that a
. 所以每当你的
a
是活动的,上面的CSS将被应用到.news-box
孩子说的a
。
Your magic code can be something like this: 您的魔术代码可以是这样的:
a{ width:100px; margin:10px; border:1px solid #ddd; display:inline-block; text-decoration:none; text-align:center; text-transform:uppercase; color:#fff; } .news-box{ padding:10px; background-color: #21B4C3; background-image: -webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent); background-image: -o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent); background-image: linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent); -webkit-background-size: 40px 40px; background-size: 40px 40px; } a:active .news-box{ -webkit-animation: magicbg .92s infinite; -moz-animation: magicbg .92s infinite; -o-animation: magicbg .92s infinite; animation: magicbg .92s infinite; } @-webkit-keyframes magicbg { from { background-position: 0 0; } to { background-position: 100% 0; } } @-o-keyframes magicbg { from { background-position: 0 0; } to { background-position: 100% 0; } } @-moz-keyframes magicbg { from { background-position: 0 0; } to { background-position: 100% 0; } } @-keyframes magicbg { from { background-position: 0 0; } to { background-position: 100% 0; } }
<a href="#"> <div class="news-box">Button1</div> </a> <a href="#"> <div class="news-box">Button1</div> </a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.