How to make css a:active work after the click?
From your demo link in the comments on another answer, JavaScript will not be of any help, it should be done in your PHP code.
Something in the lines of:
<a <?php if (this_tab_is_selected){ ?>class='active' <?php } ?>href='LINK_TO_TAB' >
TAB_NAME
</a>
Mentioning that changing tabs is redirecting to another page could have helped with better responses from the start xD
Depending on your code and how you are creating the tabs, you need to change the this_tab_is_selected
to a code that returns true
for the selected tab.
P.S. You still need to make the modification mentioned in the other answer in your CSS. (Which is to change #navigation a:active
to #navigation a.active
)
CSS :active only works during a click
your can try this by using checkbox if you want to do it with NO js only css
[type="checkbox"]{ display:none;}.fave { width: 70px; height: 50px; background: url(https://cssanimation.rocks/images/posts/steps/twitter_fave.png) no-repeat; background-position: 0 0; display: inline-block; }
[type="checkbox"]:checked ~ .fave { background-position: -3519px 0; transition: background 1s steps(55);}
<input type="checkbox" id="cb1"><label class="fave" for="cb1"></label>
keeping a: active until another link is clicked
HTML: (Added onclick="clickSingleA(this)"
and class="single"
attributes.)
To have one of the links activated by default, just add active
class
<div align="right"><a onclick="clickSingleA(this)" class="single active" href="me1.cfm?pic_ws=80&typ=1" target="mnfrm3">ME1</A></div><br>
<div align="right"><a onclick="clickSingleA(this)" class="single" href="me2.cfm?pic_ws=80&typ=1" target="mnfrm3">ME2</A></div><br>
<div align="right"><a onclick="clickSingleA(this)" class="single" href="me3.cfm?pic_ws=80&typ=1" target="mnfrm3">ME3</A></div><br>
CSS: (added a.active)
a {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #C65B05;
}
a:hover, a.active
{
text-decoration: none;
color: #03B003;
}
JavaScript: (function to activate links, and remove old active)
function clickSingleA(a)
{
items = document.querySelectorAll('.single.active');
if(items.length)
{
items[0].className = 'single';
}
a.className = 'single active';
}
How can I keep a css :active style after I release my mouse on a bootstrap navbar li
You can't keep :active
after releasing the mouse button because that is not how it works.
Here are a couple of options, one javascript/jquery, the other CSS and HTML
Jquery
Clean, concise and flexible
js
$(document).ready(function() {
$(".nav-pills a").click(function() {
$(".nav-pills a").removeClass("active");
$(this).addClass("active");
});
});
css
.nav-pills > li > a:active,
.nav-pills > li > a.active {
border-bottom: 5px solid white;
}
$(document).ready(function() { $(".nav-pills a").click(function() { $(".nav-pills a").removeClass("active"); $(this).addClass("active"); });});
.menupartial { background-color: #16749F; opacity: .9; width: 100%;}.menupartial a { color: lightgrey; font-weight: bold;}.nav-pills > li > a { border-radius: 0;}.nav-pills > li > a:hover { border-radius: 0; background-color: #16749F; color: white;}.nav-pills > li > a:active,.nav-pills > li > a.active { border-bottom: 5px solid white;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><div class="row menupartial"> <div class="col-md-12"> <ul class="nav nav-pills"> <li>@Html.ActionLink("User", "UserProfile", "Account")</li> <li>@Html.ActionLink("Profiles", "Index", "Profile")</li> <li>@Html.ActionLink("Spaces", "Index", "Space")</li> <li><a href="#">Your Schedules</a> </li> <li><a href="#">Your Messages</a> </li> <li><a href="#">Your Groups</a> </li> <li><a href="#">Your Friends</a> </li> </ul> </div></div>
CSS change button style after click
If you're looking for a pure css option, try using the :focus pseudo class.
#style {
background-color: red;
}
#style:focus {
background-color:yellow;
}
Related Topics
Comma in CSS, Multiple Selectors Using the Same CSS
How to Change <Input Type="File"> Style
Responsive Clip-Path with Inline Svg
(Really) Long Background Image Does Not Render on iPad Safari
Fill Only Half a Star with Svg
How to Change Color of Icons in Font Awesome 5
Change Outline for Outlinedinput with React Material-Ui
Are Flex Items Block Level Element
Bootstrap Change Order of Columns
How to Reset a CSS Variable (Aka Custom Properties) and Use the Fallback One
Less Mixin a Variable Class Name
Print Background Colours in Chrome
Icon Fonts Not Loading in Ie11
Repeat CSS Background Image a Set Number of Times
Cross-Fade Between Images with CSS in Loop
How to Use the New Affix Plugin in Twitter's Bootstrap 2.1.0