Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input:focus not working

Tags:

html

css

focus

At first my input focus was working just fine, now all of a sudden when I add a couple of more styles to my input, it suddenly stops working. I've only added the 'input[type="text"] and border-radius and padding and some margins since when it was working. When you click each form element, nothing happens even though I have a rule for focus(which you can find near the bottom of the code). Is there any workaround for this?

form{
  position: absolute;
  left: 50%;
  color: white;
  margin-left: -180px;
  padding: 15px 30px 15px 30px;
  background-color: #26004d;
  border-radius: 7px;
  margin-top: 10px;
  width: 300px;
}

label{
  float: left;
  text-align: right;
  margin-right: 15px;
  width: 100px;
}

input:focus {
  border: 2px solid #862d59;
}

input[type="submit"]{
  width: 50%;
  background-color: #862d59;
  color: white;
  margin-top: 5px;
  padding: 12px 12px;
  border: none;
  cursor: pointer;
}

input[type="text"]{
  width: 100%;
  padding:  12px 12px;
  margin: 4px 0;
  border: 1px solid #ccc;
  border-radius: 6px;
  //box-sizing: border-box;
}
<div id="formholder1">
  <form>
    <div class="single-field">
	  <label for="Username">Username:</label>
	  <input name="Name" type="text"></input>
    </div>
    <div class="single-field">
      <label for="Password">Password:</label>
      <input name="Password" type="text"></input>
    </div>
    <input type="submit" value="Login">
  </form>	
</div>	
like image 513
Shinji-san Avatar asked Oct 20 '25 11:10

Shinji-san


2 Answers

Use this input[type="text"]:focus { border: 2px solid #862d59; }

learn it - http://www.w3schools.com/cssref/trysel.asp?selector=:focus

example - https://css-tricks.com/snippets/css/glowing-blue-input-highlights/ now its working

form{
	position: absolute;
	left: 50%;
	color: white;
	margin-left: -180px;
	padding: 15px 30px 15px 30px;
	background-color: #26004d;
	border-radius: 7px;
	margin-top: 10px;
	width: 300px;
}

label{
	float: left;
	text-align: right;
	margin-right: 15px;
	width: 100px;
}
input[type="text"]:focus {
	border: 2px solid #862d59;
}
input:focus {
	border: 2px solid red;
}

input[type="submit"]{
 width: 50%;
 background-color: #862d59;
 color: white;
 margin-top: 5px;
 padding: 12px 12px;
 border: none;
 margin-left:-10px;
 cursor: pointer;
}

input[type="text"]{
	width: 100%;
	padding:  12px 12px;
	margin: 4px 0;
	border: 1px solid #ccc;
	border-radius: 6px;
  margin-left:-15px;

	//box-sizing: border-box;

}
<div id="formholder1">

			<form>
				<div class="single-field">
				<label for="Username">Username:</label>
					<input name="Name" type="text"></input>
				</div>

				<div class="single-field">
					<label for="Password">Password:</label>
					<input name="Password" type="text"></input>

				</div>
				<input type="submit" value="Login">
			</form>	
		</div>	
like image 121
Codeone Avatar answered Oct 22 '25 02:10

Codeone


Put Your :focus property after input.

input[type="text"]:focus {
    border: 5px solid #862d59;
}

form{
	position: absolute;
	left: 50%;
	color: white;
	margin-left: -180px;
	padding: 15px 30px 15px 30px;
	background-color: #26004d;
	border-radius: 7px;
	margin-top: 10px;
	width: 300px;
}

label{
	float: left;
	text-align: right;
	margin-right: 15px;
	width: 100px;
}


input[type="submit"]{
 width: 50%;
 background-color: #862d59;
 color: white;
 margin-top: 5px;
 padding: 12px 12px;
 border: none;
 cursor: pointer;
}

input[type="text"]{
	width: 100%;
	padding:  12px 12px;
	margin: 4px 0;
	border: 1px solid #ccc;
	border-radius: 6px;
	box-sizing: border-box;

}
input[type="text"]:focus {
	border: 5px solid #862d59;
}
<div id="formholder1">

			<form>
				<div class="single-field">
				<label for="Username">Username:</label>
					<input name="Name" type="text"></input>
				</div>

				<div class="single-field">
					<label for="Password">Password:</label>
					<input name="Password" type="text"></input>

				</div>
				<input type="submit" value="Login">
			</form>	
		</div>
like image 32
Gautam Jha Avatar answered Oct 22 '25 01:10

Gautam Jha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!