2

I am creating a drop down menu, that will be next to a box with a placeholder within it. I would like both of the text within the boxes to appear the same. I would like to know, how do I find out the default properties from the text box, so that I may use those properties in my drop down menu?

<input type="text" placeholder="Gray Default">

<select>
  <option>Black Default
  </option>
</select>

I want the style of both boxes to appear the same. I just don't know how to find the exact default settings

Umesh Sehta
  • 10,555
  • 5
  • 39
  • 68

2 Answers2

1

To check default browser styles you can use window.getComputedStyle(). Unfortunately, each browser uses its own pseudoclass/pseudoelement name for placeholders:

IE up to version 9 and Opera up to version 12 do not support any CSS selector for placeholders.

(taken from this great answer)

Example code

I used this code to discover that on my Firefox placeholder has black color and opacity of 0.54.

var firstInput = document.getElementsByTagName('input')[0],
    placeholderStyles = window.getComputedStyle(firstInput, '::-moz-placeholder');
console.log('Color: ' + placeholderStyles.getPropertyValue('color'));
console.log('Opacity: ' + placeholderStyles.getPropertyValue('opacity'));
<input type="text" placeholder="blah, blah">
Community
  • 1
  • 1
Luke
  • 1,369
  • 1
  • 13
  • 37
0

Try this

select {
  color:  rgb(0,0,0);
  opacity:0.54;

}
<input type="text" placeholder="Gray Default" >

<select>
  <option>Changed to Gray
  </option>
</select>
Kishan
  • 1,182
  • 12
  • 26