Css input:focus only on first click - css

Does anybody know a way to input:focus an element only on first click?
<style>
input[type='text'].error:focus{border-color:#f00}
</style>
So, if the user "focus out" it returns to the original border color.
Thanks in advance for any hint.
Edit
I wasn't sure at all. Thanks #blender.
I think the easist way to do it is using jquery or similar, right?

I am confused as to what you mean by "only on first click". If you want to style an input on click, you can just use this CSS:
input[type="text"].error:focus { border-color: #f00; }
And this HTML:
<input type="text" class="error" />
That will style the input border given it has the class of error (if you are adding/removing the class dynamically that is).
However, if you are styling for errors (like if the user hasn't filled out the form), you might want to try something like this:
input[type="text"]:invalid { border-color: #f00; }
input[type="text"]:valid{ border-color: #; } //If form is filled in
Then in your HTML:
<input type="text" required />
Does that help answer your question a little bit?

As #Blender said, it does not seem possible in pure CSS.
I would suggest to handle focusin and focusout events to add a class to an element and use data- attributes to get if element was already clicked or not.
Have a look at this jsFiddle.

For all who have the same or a similar question, here's is a possible jQuery solution:
$('input').on('focusout',function(){
$(this).removeClass('error');
});
This will remove the error class on :focus out.
When the user :focusin another time the input element, it will return to the default color.
Example default border-color with css:
<style>
input[type='text']:focus {border-color: black;}
</style>

Related

Angular typescript on blur input filed to added background CSS not work

Angular Type script, When I enter the value on the input filed and after I added CSS at the on blur to input filed background change but its not working correctly, dose any one know how to do that correctly?
html
<input nz-input placeholder="Type here" ng-class={red:blur} (blur)="UpdateInvoice(data,$event)" value="{{data.invoiceNum}}" style=width:200px />
css
.red {
background-color: red;
}
I assume blur is a variable that is set in the UpdateInvoice function.
If that is true, you should use
[ngClass]="{'red': blur }"
to toggle this class. More information on how to use ngClass can be found here: https://angular.io/api/common/NgClass

clicking on label 'for' both anchor tag and input tag

I cannot get this work, looks like not possible, that's why i'm asking...
This is the CSS used:
label.btn {
cursor:pointer;
display:inline-block;
}
label.btn>input[type=checkbox] {
display:none;
}
label.btn>input[type=checkbox]:checked~b {
background:red;
}
/* not relevant, just for testing purpose */
#divtest {
margin-top:1500px
}
Following HTML code will check the input, and then style for <b> tag is applied:
<a href="#divtest" id="anchor">
<label class="btn">
<input type="checkbox"/><b>Click should scroll to '#divetest' element and check input for styling!</b>
</label>
</a>
DEMO styling
If i add attribute 'for' to the label to target the anchor tag, the default browser scrolling works, but then no more styling applied:
<label class="btn" for="anchor">
DEMO anchor
Now, the obvious question:
Can i get these both behaviours working together in pure CSS?
An input element inside an a violates common sense as well as HTML5 CR. Nesting two interactive elements raises the issue which element is activated on mouse click.
Instead of such construct, use valid and sensible HTML markup. Then please formulate the styling question in terms of desired or expected rendering vs. actual rendering, instead of saying that “this” “does not work”.
This won't work since the Input:checkbox is INSIDE the <label>. Browsers will set focus on the input upon a click on the label.

css white-space property in textarea?

I want to use the white-space CSS property in an HTML textarea.
Basically if someone types a bunch of text with line breaks in a textarea, and then submits this data to be stored in MySQL, I want to use the white-space CSS property to display those line breaks in the textarea. But when I try it it's not working and just displays the text all together in one big paragraph, without any breaks or anything. Is there a way to do this?
<form action="includes/changebio.php" method="post" id="form1">
<textarea id="bio" style="width: 440px;
margin-top:3px;
text-align:left;
margin-left:-2px;
height: 120px;
resize: none;
outline:none;
overflow:scroll;
**white-space:pre-line;**
border: #ccc 1px solid;" textarea name="bio" data-id="bio" maxlength="710" placeholder="<?php echo stripslashes($profile['bio']); ?>"></textarea>
<input type="image" src="assets/img/icons/save-edit.png"class="bio-submit" name="submit" value="submit" id="submit"/>
</form>
textarea{white-space:pre}
When I've seen this, it's because your textarea is inheriting a white-space:nowrap from something. It can also be complicated by a wrap="no" on the textareas which can be useful sometimes.
The default behavior for a textarea nowrap is pre, so simply setting the css as above at the bottom of your styles will override anywhere that is setting the white-space.
If you inspect your textarea element, you'll most certainly find that somewhere in the hierarchy you're setting the nowrap property somewhere on some type of element that is overriding the default textarea behavior.
Don't.
<textarea> elements already handle whitespace literally. There is no need to try and take things into your own hands.
Things seem to be working ok for me... Tossed this into a codepen just to test it. Newline characters appear fine within the textarea when added directly.
Don't know what's going on. Is PHP stripping newline characters? Are you using double quotes around whatever you are passing in through $profile['bio']?
Here's an answer that might help you: The .val() of a textarea doesn't take new lines into account
The last response, in particular. Based on your code, it doesn't sound like the .replace() method is what you need (but I could be wrong... maybe I'm not understanding what you are doing).
one line of jquery will solve the problem
$('#bio').text('');
or Javascript
document.getElementById("bio").innerText = '';

No reaction from my HTML buttons in phonegap

I have three HTML buttons and when I click on them there is no outer glow and they don't do anything.
I have also tryed to style them but they stay with the default design. I have just used ordinary code I just don't have a clue what's wrong with them
<input type="button" value="Proceed">
<input type="button" value="Cancel">
Don't use , instead use with CSS to create your buttons so they react to touch. It'll require some javascript as even most mobile browsers don't properly map touch events to the CSS :active pseudoclass.
Your "button":
<a class="button" id="yourButton">Button</a>
Some very basic CSS to toggle the background and text color on touch:
a.button {
color:#fff;
border:0px;
padding:5px;
background:#000;
}
a.button-active {
background:#fff;
color:#000;
}
And here's the javascript you would call in your onload on deviceready handler. I'm using xuijs here (xuijs.com), but you can use jQuery or any other javascript to add and remove classes:
x$('.button').on('touchstart', function(e) {
x$(e.currentTarget).addClass('button-active');
} );
x$('.button').on('touchend', function(e) {
x$(e.currentTarget).removeClass('button-active');
} );
This is a very basic example. Once you have this all setup, you can make any changes you want to the CSS to determine how the button will look when it is active and inactive.
Hmmm.. Your question is not that clear. But if you only want a glow in your buttons, you can take a look at how Formalize does it.
Here's a page showing the button glow effect (when pressed).
Update:
Oooops, sorry, missed the "PhoneGap" part. The solution I gave above is only for normal html forms, I don't have experience with using phonegap yet. cheers. :)

CSS: can I hide the borders of the searchbox?

Can I hide the borders of the searchbox ? I would like it completely white, just the text should be visible. And I need a solution for all browsers.
See the picture:
http://dl.dropbox.com/u/72686/searchBox.png
you can add this
<input name="textfield" type="text" class="hide_border" id="textfield" />
css
.hide_border{
border:none;
*border:solid 1px #FFF;
}
By using a standard checkbox I am not sure whether you get this effect in a cross browser way. You can use a custom element and make it act like a checkbox using CSS and javascript.
See this one which uses jquery
Fancy custom radio and checkbox
I'm not sure if I understand correctly. Why don't you just hide the checkbox and leave the label ? (Later using javascript and such you can redisplay the checkbox)
Checkboxes can not be styled in all browsers. The common solution is to use two images, toggling between the two when clicked (and updating a hidden field as necessary).
<style>
.inputsearch input
{
background-color: #FFF;
border: none;
}
</style>
<div class="inputsearch" style="text-align:left;">
<input type="text" value="HEy there ">
</div>
Styling checkboxes isn't doable in a crossbrowser fashion without some jQuery, have a look at this: Custom checkboxes with jQuery. It's the only way to do it, standard checkboxes cannot be styled in all browsers.

Resources