styling the optional input fields - css

I have a web form where some input fields are required and some are optional. I can give style the required fields as I expect but can't the optional ones.
When the optional fields have a valid input it will turn green(for instance). And it works with this code
input:optional:valid{
background: #AAB69B
}
But generally like as first loading they will be in another color. For this, I am trying this code
input:optional{
background: #f19999
}
But this doesn't work. I can't select the optional fields when they have no input. Unfortunately, with no input value they get the background as I set for the valid input. When I start typing , it get my expected invalid background. And when the input gets valid, the field gets valid background (it works).
Please, help !
Demo Link : http://bdlance.byethost9.com/front-end%20form%20validation%20with%20html5/

Taking a look at your form styles, I've seen that your background color is similar for both valid and invalid pseudo classes:
input:required:invalid, textarea:required:invalid{
background: #AAB69B; // same
}
input:required:focus:invalid, textarea:focus:invalid{
background: #AAB69B; // same
}
input:required:valid, textarea:required:valid{
background: #AAB69B; // same
}
input:optional, select {
background: #f19999;
}
input:optional:valid{
background: #AAB69B; // same
}
Try this instead:
input:required:invalid, textarea:required:invalid{
background: #f19999;
}
input:required:focus:invalid, textarea:focus:invalid{
background: #f19999;
}
input:required:valid, textarea:required:valid{
background: #AAB69B;
}
input:optional, select {
background: #f19999;
}
input:optional:valid{
background: #AAB69B;
}
Sorry, but your CSS file is not the best, Please do dedicate more time to learn CSS. Here are some good resources (the order matters):
https://developer.mozilla.org/en-US/docs/Learn/CSS
https://flukeout.github.io/
https://smacss.com/
https://en.bem.info/methodology/css/

Related

Google App Maker - How to keep constant space between the label and input of a dropdown/textbox widget?

I have a field in a form with label/display name:
"I can confirm that this supply is not subject to restrictions under the Test Group, or be of a specialist nature, and as such require other checks that this method does not support."
I am using a dropdown widget with options Yes and No to display it.
I could wrap the label by trying below css.
.app-AddRequest-Field15-Label {
white-space: normal;
}
But now the space between the input and label is very less. Even if I put a margin top to the input when in mobile view the label wraps even more and the space still remains very less/ both override.
Images with borders
Label border: black
Input border: Orange
I want to keep a constant space in all views. Please suggest.
I mocked up a solution that works for up to four lines of data in a label. These are the steps you need to follow:
1.) In the global css, make sure you have the following lines:
.app-Dropdown-Label {
white-space: normal;
}
.twoLinesLabel{
top: -15px !important;
}
.threeLinesLabel{
top: -30px !important;
}
.fourLinesLabel{
top: -45px !important;
}
2.) On any of the client scripts place the following:
function adjustLabel(widget){
var label = widget.getElement().children[0];
var ch = label.clientHeight;
var lines = Math.floor(ch / 15);
switch(lines){
case 2:
label.classList.add("twoLinesLabel");
break;
case 3:
label.classList.add("threeLinesLabel");
break;
case 4:
label.classList.add("fourLinesLabel");
break;
}
}
3.) On the onAttach event handler of any dropdwon you need this adjustment, place the following:
adjustLabel(widget);
The only problem with that approach is that in the UI you won't be able to see the necessary space your field requires so that it don't overflows with the previous field. So you'll have to preview the app and make adjustements accordingly.
Another way is to make sure that your CSS looks like this instead:
.app-Dropdown-Label {
white-space: normal;
}
.twoLinesLabel label{
top: -15px !important;
}
.threeLinesLabel label{
top: -30px !important;
}
.fourLinesLabel label{
top: -45px !important;
}
Then on the Display category of the property editor, simply add the correspoding style to the dropdown. That way you will be able to see the changes in the editor immediately.
Whatever way you choose, the result is the following:

Use background image using css file in ReactJs

I have a react application in which on checking certain checkboxes I am adding or changing a certain image icon.
.checkbox1:checked ~ .icon-span {
background: url('../../../../assets/images/icon_plus.svg');
}
Which is giving me this:
background: url([object Module]); //invalid property value
But path is correct, how do I correct this?
This should work
.checkbox1:checked ~ .icon-span {
background: url(${require("../../../../assets/images/icon_plus.svg")});
}

Priority of one css attribute value over another

For a button I have 3 possible classes: "state-normal", "state-focus" and "state-hover".
All have the same attributes (background, border, ...), but different values for the
attributes.
If a button gets "state-focus", I do not want to remove the class "state-normal".
If a button is "state-focus" and gets "state-hover", I do not want to remove the class
"state-focus".
In the browser language specification you can give a "quality"/priority to a language:
"Accept-Language: da, en-gb;q=0.8, en;q=0.7"
It would be great to do the same also in css:
.state-normal { background-color: #aaaaaa;q=0.5 }
.state-focus { background-color: #bbbbbb;q=0.7 }
.state-hover { background-color: #eeeeee;q=0.9 }
I know that there is nothing in CSS.
But, I know in jQuery UI they have kind of this, because they don't remove "ui-state-default" when they assign "ui-state-focus" to an element. How do they do it?
Is there another way to implement this with a trick (WITHOUT !IMPORTANT).
Thanks alot in advance
You can do this using CSS.
.state-normal { background-color: #aaaaaa;q=0.5 }
.state-normal.state-focus { background-color: #bbbbbb;q=0.7 }
.state-focus.state-hover { background-color: #eeeeee;q=0.9 }
But this implies that all classes mentioned in the rule will be present, i.e. an element will have both classes present. So an element with class state-focus will not have the background-color set as per the rule.
If you want to avoid that, then you can do this instead:
.state-normal { background-color: #aaaaaa;q=0.5 }
.state-focus, .state-normal.state-focus { background-color: #bbbbbb;q=0.7 }
.state-hover, .state-focus.state-hover { background-color: #eeeeee;q=0.9 }
EDIT: As per OP's request
CSS Specificity
CSS Selectors - MDN
Similar answer

LessCSS: Nesting functions within concatenated classes

I'm having real issues with getting LessCSS to process a file that has a series of nested rules using the "&" concatenation selectors.
For example, the following will work without errors:
.grey-table {
background: #EDEDED;
tr {
th {
background: #DEDEDE;
}
td {
color: #888;
}
&:nth-child(odd) {
td {
background-color: #F9FCFF;
}
}
&:nth-child(even) {
td {
background-color: #EDF5FF;
}
}
&:hover {
td {
background-color: #DFEAF9;
}
};
}
}
However if I change the colours to be a function (of any sort - predefined or mixin), I get the error
"Syntax Error on line 12 - undefined"
.grey-table {
background: desaturate(#EDEDED, 100%);
tr {
th {
background: desaturate(#DEDEDE, 100%);
}
td {
color: desaturate(#888, 100%);
}
&:nth-child(odd) {
td {
background-color: desaturate(#F9FCFF, 100%); <------ Line 12
}
}
&:nth-child(even) {
td {
background-color: desaturate(#EDF5FF, 100%);
}
}
&:hover {
td {
background-color: desaturate(#DFEAF9, 100%);
}
};
}
}
I cannot find any reference material on this but I'm sure I can't be the only one?
Many thanks.
i usually define the colors first and then call them in the functions:
#mycolor: #F9FCFF;
desaturate(#mycolor, 100%);
I am sorry, but there are no errors with your code on the less page:
http://less2css.org/
Try pasting it in (without your <---line 12) and you will see it works.
MAybe you are using some javastript that interacts with the less script on your page.
Edit:
You also have an semicolon at the end that breaks older versions (<=1.3.1) of the less parser.
If I take it out it parses well through al versions ... and I do not manage to reproduce your error.
I'm an idiot and had not noticed the tab on line 12 after the colon.
That's what was causing the error, but only when there was a less css mixin/variable. Apologies to all.
I agree with Martin, I cannot reproduce your error using your code above and the compiler at http://less2css.org/. The only ways I can reproduce a syntax error message on line 12 are:
Remove the colon after the background-color property.
Add some non-comment related characters after the end semi-colon (like your note <--- line 12 is invalid, but I'm sure you put that in for illustration above).
Add an end quote after either (a) the color, (b) the percentage, or (c) the parenthesis. An example of (b) - 100%'. There may be some other characters that would cause it too, but some just print right out into the css wihtout a syntax error.
A character separated by a space or other invalid character for a property name before the property name, like y background-color or *background-color.
Obviously, none of those exist in your code shown above, but you might double check that your actual code does not have some extra characters or missing characters that might be causing the issue.

CSS - Match a whole attribute value

HTML
<div data-whatever='something cols-16 else'>
</div>
This works:
Will work - CSS
[data-whatever*='cols-1'] {
background: red;
}
It will find the div and make it red.
Will not work - CSS
[data-whatever='cols-16'] {
background: red;
}
It will not find the div because there are other stuff in there as well.
Problem
The problem with the working CSS, is that it matches both cols-16, cols-1 and any other that starts with cols-1.
Question
Is it possible to find an attribute value, exact match?
In order to target the class cols-16 (even when it appears with other classes)
and not target the cols-1 class use this:
[data-whatever~='cols-16'] {
background: green;
}
You can see this working in this fiddle.
For more info see this post (Goto #16. - X[foo~="bar"]
The tilda (~) symbol allows us to target an attribute which has a
spaced-separated list of values.
try this:
[data-whatever~='cols-1'] {
background: red;
}
It worked for me if I didn't missunderstand your question
Edit: I just remembered the ~= randomly, tried it, and pasted it.
But I just googled a bit (I had curiosity and found This, it's quite interesting)
To ensure that it only matches cols-1 and not cols-16 without relying on the cols-16 style overriding the cols-1 style (below), you could:
[data-whatever='cols-1'],
[data-whatever^='cols-1 '],
[data-whatever*='cols-1 '],
[data-whatever$='cols-1'] {
background: red;
}
This matches data-whatever="cols-1", data-whatever="... cols-1", data-whatever="cols-1 ..." or data-whatever="... cols-1 ...".
JSFiddle example.
Thanks to aleation's answer: data-whatever~="cols-1" achieves the same as the above in just one selector.
--
At any rate your cols-16 styling could overwrite your cols-1 styling anyway, depending on the order it was presented:
[data-whatever*='cols-1'] {
background: red;
}
[data-whatever*='cols-16'] {
background: blue;
}
/* cols-1 will be red. cols-16 will be blue */
JSFiddle example.

Resources