Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS outline width not working

I am trying to set outline width of the input element on focus. Outline width stays the same (like it is default setting which can not be changed), no matter of my setting.

Here is example from code pen

And here is part from css where I am trying to set outline-width on focus:

input:focus {
  outline-width: 0.1px;
  outline-color: #725b44;  
}

EDIT:

I've just forgotten to include line style (solid, dotted...). Now it works. One thing is still strange to me. Why is outline inside element? Isnt' the outline defined as 'a line that is drawn around elements (outside the borders) to make the element "stand out".'

Here from my example outline looks like this. I thought it's going to be around element, but it's inside:

enter image description here

like image 911
FrenkyB Avatar asked Dec 10 '22 15:12

FrenkyB


2 Answers

Add outline-style: solid to your css.

Since the default style for the outline-style property is none, you will have to set it as well (none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset|initial|inherit). Best value you can use for the style is solid, but that's a matter of preference.

Example for the behavior:

input {
  font-size: 22px;
  padding: 5px 3px;
  color: #666;
}

input.with-outline-style:focus {
  outline-width: 3px;
  outline-style: solid;
  outline-color: #725b44;
  /* You could also use the shorthand: */
  /* outline: 3px solid #666; */
  /*       width style color */
}

input.without-outline-style:focus {
  outline-width: 3px;
  outline-color: #725b44;
}

body {
  background-color: #fd9;
}

div {
  padding: 5px 10px;
}
<div>
  <input type="text" class="with-outline-style" value="outline-style set to solid" />
</div>

<div>
  <input type="text" class="without-outline-style" value="outline-style not set" />
</div>

Update

The outline-width setting doesn't work without specifying outline-style: if no outline style is set, the browser will render the outline in its default style (which could be anything, such as a dotted rectangle in IE, a shaded rectangle in Chrome, or even nothing).

like image 68
beerwin Avatar answered Jan 01 '23 04:01

beerwin


Use outline-style

input:focus {
  outline-width: 0.1px;
  outline-color: #725b44;  
  outline-style: dotted;
}
like image 45
Mani Avatar answered Jan 01 '23 04:01

Mani