Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve placeholder CSS difference across different browsers?

I am using Twitter bootstrap CSS. Below you can see how the same code is displayed differently with FireFox and Chrome.

This is quite strange. Firebug tells me that the placeholder's css is set like this to light grey:

:-moz-placeholder {
    color: #999999;
}

This should affect all placeholders within all elements as its correctly done in Chrome. But in Firefox why are textareas correctly applied, but input is not? How can I fix this?

<input id="id_referred_by" type="text" maxlength="50" name="referred_by" placeholder="...was referred by?">

<textarea id="id_contacts_interests" name="contacts_interests" cols="40" placeholder="Any particular interests?" rows="4"></textarea>

Chrome:

enter image description here

Firefox:

enter image description here

update:

The comments below gave me an idea:

Input has unlike textarea the color: #9999 entry crossed out, which means something is overriding it.

select, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
    color: #555555;
    display: inline-block;
    font-size: 13px;
    height: 18px;
    line-height: 18px;
    margin-bottom: 9px;
    padding: 4px;
}

It is in fact this color: #555555;. When I disable it in firebug, it all works. How comes Chrome doesn't care about this but Firefox do? Any tips how fix this across both browsers? I am still new to css.

like image 849
Houman Avatar asked Jul 04 '12 18:07

Houman


People also ask

How do I inspect a placeholder in Chrome?

Check the "Show user agent shadow DOM" checkbox and reload your page. You should now see the placeholder html output in your dev tools when you view the elements tab. Clicking on the placeholder html will bring up the applied styles for you to view or edit.

How do I change placeholder position in CSS?

In most of the browsers, placeholder texts are usually aligned in left. The selector uses text-align property to set the text alignment in the placeholder. This selector can change browser to browser.

How can I change placeholder color of specific input?

In most browsers, the placeholder text is grey. To change this, style the placeholder with the non-standard ::placeholder selector.

What is the placeholder pseudo-element used for?

The ::placeholder pseudo-element represents placeholder text in an input field: text that represents the input and provides a hint to the user on how to fill out the form. For example, a date-input field might have the placeholder text YYYY-MM-DD to clarify that numeric dates are to be entered in year-month-day order.


1 Answers

The problem is that Firefox change the opacity of the field, and with that you think its a different color, but its not... add "opacity:1;" and it will work exactly the same in all browsers

input:-moz-placeholder {
    color: #999999;
    opacity: 1;
}

input::-moz-placeholder {
    color: #999999;
    opacity: 1;
}
like image 89
Vinícius Moraes Avatar answered Oct 21 '22 17:10

Vinícius Moraes