简体   繁体   English

使用CSS3或JavaScript单击时,如何“突出显示”此CSS按钮?

[英]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

Edit: 编辑:

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.

相关问题 如何冻结在 CSS3、Javascript 中单击的下拉菜单? - How do I freeze a dropdown thats clicked in CSS3, Javascript? 如何将此CSS3翻译为Javascript? - How can I translate this CSS3 to Javascript? 当文档使用javascript加载时,如何执行css3转换? - How can i execute a css3 transition when the document loads using javascript? 当使用html和css单击按钮图像时,如何使用按钮图像获取按钮图像源 - how can I use button images to get the button image source when they are clicked using html and css 单击按钮时如何删除CSS部分 - How can I remove a css portion when a button is clicked 我需要使用 HTML、CSS 和 Javascript 制作一个按钮,以便在单击按钮时将字体颜色从红色变为红色 - I need to make a button using HTML, CSS, and Javascript to change font color from to red when the button is clicked 在a.html中单击按钮并仍然使用相同的javascript文件时,如何在b.html中播放css动画? - How can I play a css animation in b.html when a button is clicked in a.html and still use the same javascript file? 如何使用CSS3和Javascript创建双范围滑块? - How can I create a dual range slider using CSS3 and Javascript? 如何使用 HTML5、CSS3、Javascript/Jquery 单击此导航栏跟踪项? - How do I make this navigation bar track item clicked with HTML5, CSS3, Javascript/Jquery? 如何使用 CSS 突出显示 HTML 按钮? - How do I highlight a HTML button using CSS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM