Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML- Select box on focus highlight border

Tags:

html

css

I'm trying to highlight the border of the select box/div when that box is in use to select an item

Here's the code on hTML side

  <div class="styled-1">                   
      <select>
          <option value="1">OPTION - 1</option>
          <option value="2">OPTION -2 </option>
          <option value="3">OPTION - 3</option>
      </select>
  </div>

Here's the CSS

.styled-1 select {
    width: 312px;
    padding-top: 5%;
    padding-bottom: 5%;
    padding-left: 5%;
    border: none;
    left: 50px;
    margin-left: 20px;
    margin-right: 20px;
    border-radius: 50px;
    box-shadow: 0 0 3pt 2pt #8F4A11;
    outline: none !important;
}

What is the way pout to define a CSS of the type below for ".styled-1" above?

textarea:focus {
    outline: none !important;
    box-shadow: 0 0 3pt 2pt #719ECE;
}

I tried the below but no luck

.styled-1:focus {
        outline: none !important;
        box-shadow: 0 0 3pt 2pt #719ECE;
    }
like image 358
User12345 Avatar asked Sep 11 '15 03:09

User12345


People also ask

How do I change the selection border color on focus?

Open your Contact Form settings and find “CSS/HTML code” tab: In the “CSS code” window find this line: and change it to, for example, this border: 1px solid #00FF00; where #00FF00 is hex code of the color you chose. You will get this result (borders are green):

Which selector is used to highlight the border when selection is done to that field?

Descendant selector (space)


2 Answers

:focus works on the select element; so, you can style the select element like this:

.styled-1 select:focus {
    box-shadow: 0 0 3pt 2pt #719ECE;    
}

Here's a JSfiddle showing the results: http://jsfiddle.net/n83p5qz7/

like image 183
hktang Avatar answered Oct 19 '22 18:10

hktang


You can try

$('select').focus(
    function(){
        $(this).parent('div').css('border-style','solid');
    }).blur(
    function(){
        $(this).parent('div').css('border-style','dashed');
    });

You can have a look on the Fiddle

like image 40
Mohit S Avatar answered Oct 19 '22 18:10

Mohit S