Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button's bottom border disappears when i click somewhere else on the screen

fiddle

This is my HTML code:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<button>
    <i class="fa fa-5x fa-motorcycle gobumpr_icon"></i>
</button>
<button>
    <i class="fa fa-car fa-5x gobumpr_icon"></i>
</button>

This is my CSS:

button:focus {
    border-bottom: thick solid #FFA800;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    transition: width 2s;
    -webkit-transition: width 2s;
    outline: none;
    box-shadow: none;
}

I want that border bottom to stay until the other button is being clicked. How can I do that?

like image 252
Vyshnavi Samudrala Avatar asked May 26 '16 10:05

Vyshnavi Samudrala


People also ask

What is the Border button?

The border property is used to provide the borders to the buttons for which we use border-radius property is used for styling button borders for rounding the corners of the buttons. We can also provide give double stroke by adding another border property on the inner span element by reducing the border-radius property.

How do you make a button border invisible?

You can make a button without borders in HTML. To remove them, you have to use the border property in CSS and set it to none.


2 Answers

:focus is not going to help because border will remove whenever you will click outside. For this you need to add a class on click of button that will stay unless another buttons inside the same page is clicked.

$(function() {
   var buttons = $('.button');
  
   buttons.click(function(e) {
     e.preventDefault();

     buttons.removeClass('focus');
     $(this).addClass('focus');
  });
});
.button.focus {
  border-bottom:thick solid #FFA800;
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
  transition: width 2s;
  -webkit-transition: width 2s;
  outline:none;
  box-shadow:none;    
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

<button class="button"><i class="fa fa-5x fa-motorcycle gobumpr_icon"></i></button>

<button class="button"><i class="fa fa-car fa-5x gobumpr_icon"></i></button>
like image 144
Mohammad Usman Avatar answered Sep 30 '22 17:09

Mohammad Usman


You can also do this without javascript at all :

input:checked + i{
	border-bottom:thick solid #FFA800;
	border-bottom-left-radius: 5px;
	border-bottom-right-radius: 5px;
	transition: width 2s;
    -webkit-transition: width 2s;
	outline:none;
	box-shadow:none;
}

input{
  display:none;
}
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

<label><input type="radio" name="test"><i class="fa fa-5x fa-motorcycle gobumpr_icon"></i></label>

<label><input type="radio"name="test"><i class="fa fa-car fa-5x gobumpr_icon"></i></label>
like image 38
wilovent Avatar answered Sep 30 '22 17:09

wilovent