Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Border radius on Focus input field

Tags:

html

css

how can we adjust the border radius of the input field focus.

HTML

<input type="text" class="rest" />

CSS

.rest{border-radius:15px;border:1px solid red;}
like image 231
CSS Guy Avatar asked Apr 15 '14 10:04

CSS Guy


People also ask

How do you hide input border on focus?

Answer: Use CSS outline property In Google Chrome browser form controls like <input> , <textarea> and <select> highlighted with blue outline around them on focus. This is the default behavior of chrome, however if you don't like it you can easily remove this by setting their outline property to none .

How do you change the outline radius in CSS?

CSS Syntax border-radius: 1-4 length|% / 1-4 length|%|initial|inherit; Note: The four values for each radius are given in the order top-left, top-right, bottom-right, bottom-left. If bottom-left is omitted it is the same as top-right. If bottom-right is omitted it is the same as top-left.


4 Answers

Removed the standard outline (which does not accept border-radius) and used a blue box-shadow instead:

.rest{
  border-radius: 15px;
  border: 1px solid grey;
  padding-left: 8px;
}

.rest:focus {
  outline: none;
  box-shadow: 0px 0px 2px #0066ff;
}
<input type="text" class="rest" />

codepen demo

like image 197
Le____ Avatar answered Oct 07 '22 20:10

Le____


use the :focus pseudo selector

.rest:focus{
    border-radius:0;
}

DEMO

like image 39
James Avatar answered Oct 07 '22 19:10

James


You have to disable the outline of the element focus state:

*:focus { /*OR .rest:focus*/
    outline:none;
}

Here is a FIDDLE

If you want the border-radius on the browser default focus outline you can do it only on firefox with -moz-outline-border:5px; , but this will only work on FF, however the request to implement a similar feature in WebKit was closed as WONTFIX, The plan for the future is to make the outlines follow the borders.

like image 27
Karim AG Avatar answered Oct 07 '22 20:10

Karim AG


The other answers have covered the solution, however, the supplied CSS styles do not accurately reproduce the blue ring color or size. For example, replacing:

:focus {
    outline: -webkit-focus-ring-color auto 5px;
}

With the solutions provided, results in a purple-tinted blue before and after pic. Instead, try this color:

.rest:focus {
  outline: none; 
  border-radius: 8px;  /* Your border radius here */
  box-shadow: 0px 0px 1px rgba(0,100,255,1),
              0px 0px 2px rgba(0,100,255,1),
              0px 0px 3px rgba(0,100,255,1); /* #0064FF */
}
like image 40
aRealPerson Avatar answered Oct 07 '22 18:10

aRealPerson