CSS selector for disabled elements - html

I'm working with AngularJS to set image buttons disabled/enabled.
My css selector to show them transparent isn't working.
I've started with a try it that selects a disable on an input element and there it does indeed apply the css, but not in case of my div elements.
I've added my div elements that don't work, resulting in the following code:
<!DOCTYPE html>
<html>
<head>
<style>
input:enabled {
background: #ffff00;
}
input:disabled {
background: #dddddd;
}
div:disabled {
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
</style>
</head>
<body>
<form action="">
First name: <input type="text" value="Mickey"><br>
Last name: <input type="text" value="Mouse"><br>
Country: <input type="text" value="Disneyland" disabled><br>
Password: <input type="password" name="password" value="psw" disabled><br>
E-mail: <input type="email" value="john#doe.com" name="usremail">
</form>
<div disabled="disabled">should be transparent</div>
</body>
</html>
The disabled is getting added/removed for my AngularJS html elements. So how do I get the css to apply to a div with disabled added to it?
Note: I know it's possible to duplicate the elements, use ng-if to show/hide them and apply the transparency to it with a class, but that's very ugly.

:disabled pseudo selector will work only for input elements. For div, use div[disabled] to apply css
Use
div[disabled] {
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
Demo
input:enabled {
background: #ffff00;
}
input:disabled {
background: #dddddd;
}
div[disabled] {
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
<form action="">
First name: <input type="text" value="Mickey"><br>
Last name: <input type="text" value="Mouse"><br>
Country: <input type="text" value="Disneyland" disabled><br>
Password: <input type="password" name="password" value="psw" disabled><br>
E-mail: <input type="email" value="john#doe.com" name="usremail">
</form>
<div disabled="disabled">should be transparent</div>

Select all disabled input elements (such as input, textarea, select, option, radio, checkbox, button) :
*:disabled{
//enter code here
}
Select all other disabled elements (such as div, section, p, etc):
*[disabled]{
//enter code here
}

Use the attribute selector [attribute='value'], which will work on all types of elements, compared to the pseudo-class :disabled, which only works on form elements
And in your case, where the attribute disabled doesn't have a value, you can omit it [disabled]
Note, when not using the value part in the selector, it will target elements both with and without, but as you can see the with last CSS rule, where the value part is used, it won't.
Stack snippet (here I used it on all, but you can of course keep :disabled for the input's)
input:not([disabled]) {
background: #ffff00;
}
input[disabled] {
background: #dddddd;
}
div[disabled] {
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
div[disabled='disabled'] {
color: red;
}
<form action="">
First name: <input type="text" value="Mickey"><br>
Last name: <input type="text" value="Mouse"><br>
Country: <input type="text" value="Disneyland" disabled><br>
Password: <input type="password" name="password" value="psw" disabled><br>
E-mail: <input type="email" value="john#doe.com" name="usremail">
</form>
<div disabled>
should be transparent, but doesn't have red colored text
</div>
<div disabled='disabled'>
this will both be transparent and have red colored text
</div>

For a div element you should use div[disabled="disabled"] or div[disabled]
its not an input element where you can apply :disabled

You can use div[disabled="disabled"] to select disabled div.

See Below Example :
input:enabled {
background: #ffff00;
}
input:disabled {
background: #dddddd;
}
div:disabled {
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
<form action="">
First name: <input type="text" value="Mickey"><br>
Last name: <input type="text" value="Mouse"><br>
Country: <input type="text" value="Disneyland" disabled><br>
Password: <input type="password" name="password" value="psw" disabled><br>
E-mail: <input type="email" value="john#doe.com" name="usremail">
</form>
<input disabled/>should be transparent
And aslo See this :

I would try:
*:disabled, *[disabled]{ /* ... */}
Example
*:disabled,
*[disabled] {
background: #000;
}
<input type="text" value="foo" disabled />
<input type="text" value="bar" />

Related

change color of the label when form is focused

I have this form :
<form data-required="reference" class="tag-field reference-field">
<label for="reference-tag-input">
Reference:
<input type="hidden" id="reference-tag-input" class="reference-field-tagged form-control" data-removebtn="true" name="tag-2">
<div class="tags-container"><input type="text" class="tag-input" placeholder=""></div>
</label>
</form>
And I want to colorize the lable of the form when input of the form is focused. So I used this with no luck:
.tag-field input.tag-input:focus label {
color: red;
}
How can I change the lable color when form is focused?
Use :focus-within selector:
#supports selector(:focus-within) {
form:focus-within label { color: red; }
}
<form data-required="reference" class="tag-field reference-field">
<label for="reference-tag-input">
Reference:
<input type="hidden" id="reference-tag-input" class="reference-field-tagged form-control" data-removebtn="true" name="tag-2">
<div class="tags-container"><input type="text" class="tag-input" placeholder=""></div>
</label>
</form>
Be aware that IE 11 does not support :focus-within, so this solution must be accompanied by Javascript if you need to support that dead browser.

I have a problem with focusing a child to affect a parent

I have this code in HTML:
<div class="firstname-input">
<input type="text" id="firstname" name="firstname" placeholder="First name">
<button onclick="showName()"><figure></figure></button>
</div>
I want to add border: 2px solid #f90; to .firstname-input, at focus the input
And if I write this:
.firstname-input input:focus .firstname-input {
opacity: .1;
}
This isn't working.
Use
.firstname-input:focus-within {}
and add your chosen styles

Placeholder-shown weird behaviour with type=number - Firefox

Using the :placeholder-shown attribute on an input tag, selects the state when the placeholder text is visible. This works as expected on Google Chrome with text input boxes and number input boxes.
Google Chrome:
Firefox seems to ignore this property when used on an <input type=number> field
Firefox:
Question: Why does this occur and how can it be overcome?
Demo snippet
input:placeholder-shown {
background: #000;
}
<input placeholder="example">
<input placeholder="example" value="12345">
<br>
<input placeholder="example" type="number">
<input placeholder="example" type="number" value="12345">
The :placeholder-shown is not supported in firefox on type="number", type="time", and similar.
Here is the refrence
But you can work around it by using ::-moz-placeholder
See code below:
input:placeholder-shown {
background: #000;
}
input::-moz-placeholder {
background: #000;
color: #ddd;
opacity: 1;
}
<input placeholder="example">
<input placeholder="example" value="12345">
<br>
<input placeholder="example" type="number">
<input placeholder="example" type="number" value="12345">

disabled text input not styling

I have a form with disabled text input fields that I would like to style to look normal but not allow input.
Works in Chrome, but not in FireFox or IE - is this something that can be done in FF/IE?
HTML:
<input type="text" value="test" disabled />
CSS:
input[type="text"][disabled] {
background-color: #f00;
}
You can do this:
input[type="text"][disabled],
input[type="text"]:disabled {
color: #ff0;
background-color: #f00;
}
<input type="text" value="test" disabled />
JSFiddle: http://jsfiddle.net/jonsuh/brbktnvv/

How to place the placeholder's text right?

A field has a placeholder :
<input type="text" name="clt_cin_pass" id="clt_cin_pass" maxlength="25" placeholder="CIN/Passeport" value="foo" />
How to place the placeholder's text , here CIN/Passeport, at the field's right ?
I have created a jsFiddle for you pheromix,
https://jsfiddle.net/69sp620q/1/
Html
<input type="text" name="clt_cin_pass" id="clt_cin_pass" maxlength="25" placeholder="CIN/Passeport" />
CSS
input[type='text']{
text-align:right;
}
Of course you can update this to target a class not just all input tags
/* webkit solution */
::-webkit-input-placeholder { text-align:right; }
/* mozilla solution */
input:-moz-placeholder { text-align:right; }
<input type="text" name="clt_cin_pass" id="clt_cin_pass" maxlength="25" placeholder="CIN/Passeport" value="" />