html date input without the date picker - html

I have a simple date input
<input type="date" id="sign-up-dob" class="sign-inputs" max="2999-12-31"></input>
It looks like this:
How would i get rid of the arrows and stuff to the right that open the date picker. I just want it so you can type the date with validation, thanks.

Just use the pattern attribute on a text input:
input:invalid {
color: red;
}
[type="date"]::-webkit-inner-spin-button {
display: none;
}
[type="date"]::-webkit-calendar-picker-indicator {
display: none;
}
<label>Input Date (YYYY-MM-DD):
<input type="text" pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}" />
</label>
<input type="date" />

http://jsfiddle.net/trixta/cc7Rt/ For Reference
webshim.setOptions('forms-ext', {
replaceUI: 'auto',
types: 'date',
date: {
startView: 2,
inlinePicker: true,
classes: 'hide-inputbtns'
}
});
webshim.setOptions('forms', {
lazyCustomMessages: true
});
//start polyfilling
webshim.polyfill('forms forms-ext');
//only last example using format display
$(function () {
$('.format-date').each(function () {
var $display = $('.date-display', this);
$(this).on('change', function (e) {
//webshim.format will automatically format date to according to webshim.activeLang or the browsers locale
var localizedDate = webshim.format.date($.prop(e.target, 'value'));
$display.html(localizedDate);
});
});
});
.hide-replaced.ws-inputreplace {
display: none !important;
}
.input-picker .picker-list td > button.othermonth {
color: #888888;
background: #fff;
}
.ws-inline-picker.ws-size-2, .ws-inline-picker.ws-size-4 {
width: 49.6154em;
}
.ws-size-4 .ws-index-0, .ws-size-4 .ws-index-1 {
border-bottom: 0.07692em solid #eee;
padding-bottom: 1em;
margin-bottom: 0.5em;
}
.picker-list.ws-index-2, .picker-list.ws-index-3 {
margin-top: 3.5em;
}
div.ws-invalid input {
border-color: #c88;
}
.ws-invalid label {
color: #933;
}
div.ws-success input {
border-color: #8c8;
}
form {
margin: 10px auto;
width: 700px;
min-width: 49.6154em;
border: 1px solid #000;
padding: 10px;
}
.form-row {
padding: 5px 10px;
margin: 5px 0;
}
label {
display: block;
margin: 3px 0;
}
.form-row input {
width: 220px;
padding: 3px 1px;
border: 1px solid #ccc;
box-shadow: none;
}
.form-row input[type="checkbox"] {
width: 15px;
}
.date-display {
display: inline-block;
min-width: 200px;
padding: 5px;
border: 1px solid #ccc;
min-height: 1em;
}
.show-inputbtns .input-buttons {
display: inline-block;
}
<form action="#" class="ws-validate">
<h2>1 Calendars without visible input</h2>
<div class="form-row">
<input type="date" class="hide-replaced" />
</div>
<div class="form-row">
<input type="submit" />
</div>
</form>
<hr />

Related

I want to push html input text to text(.txt) file

<!DOCTYPE html>
<html>
<title>Simple Sign up from</title>
<head>
<style>
html, body {
display: flex;
justify-content: center;
font-family: Roboto, Arial, sans-serif;
font-size: 15px;
}
form {
border: 5px solid #f1f1f1;
}
input[type=text] {
width: 100%;
padding: 16px 8px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
select {
width: 100%;
padding: 16px 8px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: #4286f4;
color: white;
padding: 14px 0;
margin: 10px 0;
border: none;
cursor: grab;
width: 48%;
}
h1 {
text-align:center;
fone-size:18;
}
button:hover {
opacity: 0.8;
}
.formcontainer {
text-align: center;
margin: 24px 50px 12px;
}
.container {
padding: 20px 0;
text-align:left;
}
span.psw {
float: right;
padding-top: 0;
padding-right: 15px;
}
/* Change styles for span on extra small screens */
#media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
</style>
</head>
<body>
<form method="post">
<h1>DSL_PROJECT</h1>
<div class="formcontainer">
<div class="container">
<label for="Rname"><strong>Requestor-name</strong></label>
<input type="text" placeholder="Enter Requestor-name" name="Rname" required>
<label for="Nname"><strong>Namespace-name</strong></label>
<input type="text" placeholder="Enter Namespace-name" name="Nname" required>
<label for="Pname"><strong>Project_ID</strong></label>
<select id="select">
<option value="default">default</option>
</select>
</div>
<button type="submit"><strong>SUBMIT</strong></button>
</div>
</form>
<script>
var select=document.getElementById("select"),
arr=["p1","p2","p3"];
for(var i=0;i<arr.length;i++)
{
var option=document.createElement("OPTION"),
txt=document.createTextNode(arr[i]);
option.appendChild(txt);
option.setAttribute("value",arr[i]);
select.insertBefore(option,select.lastChild);
}
</script>
</body>
</html>
<?php
if(isset($_POST['textdata']))
{
$data=$_POST['textdata'];
$fp = fopen('data.txt', 'a');
fwrite($fp, $data);
fclose($fp);
}
?>
From the above HTML code there are few user inputs so I have added Post method & PHP code to trigger or push input user data of html to text(.txt)file but data is not written to the text file[ I have created manually data.txt file in my local]. And in the same script added java script to add or create list.Someone help me to fix the issue. Thanks in advance.

How to create Input Field for fixed numeric value?

I want to create a simple html input field where, for a specific numeric code, the continue/submit button will work.
For example, the submit button will go to its destination url, only if the input value is "1234". If the input value is not '1234' then the submit button will not proceed to next step.
Can anyone help?
Here the sollution i found. Big thanks to themoonroy.
https://github.com/Themoonroy/Basic-functions-code.git
test this code
document.getElementById("sub").addEventListener('click', ()=>{
var num_ = document.getElementById("num")
const validate = document.querySelector('#num + span.validate');
let pattern = /^([1234]{4})$/;
if(num_.value === ''){
num_.setAttribute('required','required')
}
else if(pattern.test(num_.value)){
num_.removeAttribute('required')
validate.textContent = "valid value"
}
else{
num_.removeAttribute('required')
num_.value = ''
validate.textContent = "invalid value !"
}
})
h1 {
text-align: center
}
input[type=number],
input[type=email],
select {
width: 100%;
padding: 12px;
margin: 8px 0;
display: inline-block;
border: 1px solid black;
border-radius: 4px;
box-sizing: border-box;
text-align: center;
}
input[type=submit] {
width: 25%;
background-color: #D39D10;
color: black;
padding: 14px;
margin: 20px 250px;
border: none;
border-radius: 4px;
cursor: pointer;
text-align: center;
}
input[type=submit]:hover {
background-color: green;
}
input:invalid {
border: 2px dashed red;
}
input:invalid:required {
background-image: linear-gradient(to right, pink, lightgreen);
}
input:valid {
border: 2px solid black;
}
<div class="ourform">
<form action="/">
<label for="name">number</label>
<input type="number" id="num" name="num" placeholder="Your number...">
<span class="validate" aria-live="polite"></span>
<input type="submit" value="Submit" id="sub">
</form>
</div>

Auto move to next input field and return on backspace when input was max length

I am making an credit card input field. where I need to switch the cursor after max length of number has been input and when delete using backspace need to focus on previous field.
(function ($) {
$(".nmipay-input-field").keyup(function () {
if (this.value.length == this.maxLength) {
var $next = $(this).next('.nmipay-input-field');
if ($next.length){
$(this).next('.nmipay-input-field').focus();
}else{
$(this).blur();
}
}
});
})(jQuery);
#CheckoutCreditCard fieldset {
position:relative;
display: inline-block;
width: 100%;
border: 1px solid #C5C5C5 !important;
}
#CheckoutCreditCard .nmipay-input-field {
border:none!important;
position:relative;
}
#CheckoutCreditCard .nmipay-input-field:focus {
outline:none!important;
}
/* Change the white to any color */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
-webkit-box-shadow: 0 0 0 30px white inset!important;
-moz-box-shadow: 0 0 0 30px white inset!important;
}
#CheckoutCreditCard label {
font-family: "futura-bold";
font-size: 15px!important;
line-height: 2!important;
color: #515151!important;
}
#CheckoutCreditCard input {
color: #0a3956!important;
font-family: "futura-bold";
min-height: 50px!important;
font-size: 16px!important;
background-color: transparent!important;
-webkit-box-shadow: none!important;
-moz-box-shadow: none!important;
}
input#nmipay-card-number {
width: 54%;
}
input#nmipay-card-expiry {
width: 21%;
}
input#nmipay-card-cvc {
width: 18%;
margin-right:2px;
}
input::placeholder {
color: #c5c5c5;
opacity: 1; /* Firefox */
}
input:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: #c5c5c5;
}
input::-ms-input-placeholder { /* Microsoft Edge */
color: #c5c5c5;
}
#media (max-width: 767px){
input#nmipay-card-number {
width: 54%;
margin-right: 2px!important;
}
input#nmipay-card-expiry {
width: 20%;
padding-right: 2px!important;
}
input#nmipay-card-cvc {
width: 15%;
}
#CheckoutCreditCard input {
min-height: 45px!important;
font-size: 12px!important;
}
}
#media (max-width: 360px){
#CheckoutCreditCard input {
font-size: 10px!important;
}
#add_payment_method #payment ul.payment_methods li input,
.woocommerce-cart #payment ul.payment_methods li input,
.woocommerce-checkout #payment ul.payment_methods li input {
margin: 0 .5em 0 0;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div id="CheckoutCreditCard" class="CC_container"">
<div class="CC_input_group"">
<fieldset id="nmipay-cc-form" class="wc-credit-card-form wc-payment-form">
<input id="nmipay-card-number" class="nmipay-input-field input-text wc-credit-card-form-card-number" type="text" maxlength="20" autocomplete="off" placeholder="Card Number" name="nmipay-card-number" />
<input id="nmipay-card-expiry" class="nmipay-input-field input-text wc-credit-card-form-card-expiry" type="text" maxlength="7" autocomplete="off" placeholder="MM / YY" name="nmipay-card-expiry" />
<input id="nmipay-card-cvc" class="nmipay-input-field input-text wc-credit-card-form-card-cvc" type="text" autocomplete="off" maxlength="4" placeholder="CVC" name="nmipay-card-cvc"/>
<div class="clear"></div>
</fieldset>
</div>
</div>
You can do this by checking the length of the value and changing focus to the prev field.
if (this.value.length == 0)
$(this).prev('.nmipay-input-field').focus();
(function($) {
$(".nmipay-input-field").keyup(function() {
if (this.value.length == this.maxLength) {
var $next = $(this).next('.nmipay-input-field');
if ($next.length) {
$(this).next('.nmipay-input-field').focus();
} else {
$(this).blur();
}
}
//***** Delete Check *****//
if (this.value.length == 0)
$(this).prev('.nmipay-input-field').focus();
});
})(jQuery);
#CheckoutCreditCard fieldset {
position: relative;
display: inline-block;
width: 100%;
border: 1px solid #C5C5C5 !important;
}
#CheckoutCreditCard .nmipay-input-field {
border: none!important;
position: relative;
}
#CheckoutCreditCard .nmipay-input-field:focus {
outline: none!important;
}
/* Change the white to any color */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
-webkit-box-shadow: 0 0 0 30px white inset!important;
-moz-box-shadow: 0 0 0 30px white inset!important;
}
#CheckoutCreditCard label {
font-family: "futura-bold";
font-size: 15px!important;
line-height: 2!important;
color: #515151!important;
}
#CheckoutCreditCard input {
color: #0a3956!important;
font-family: "futura-bold";
min-height: 50px!important;
font-size: 16px!important;
background-color: transparent!important;
-webkit-box-shadow: none!important;
-moz-box-shadow: none!important;
}
input#nmipay-card-number {
width: 54%;
}
input#nmipay-card-expiry {
width: 21%;
}
input#nmipay-card-cvc {
width: 18%;
margin-right: 2px;
}
input::placeholder {
color: #c5c5c5;
opacity: 1;
/* Firefox */
}
input:-ms-input-placeholder {
/* Internet Explorer 10-11 */
color: #c5c5c5;
}
input::-ms-input-placeholder {
/* Microsoft Edge */
color: #c5c5c5;
}
#media (max-width: 767px) {
input#nmipay-card-number {
width: 54%;
margin-right: 2px!important;
}
input#nmipay-card-expiry {
width: 20%;
padding-right: 2px!important;
}
input#nmipay-card-cvc {
width: 15%;
}
#CheckoutCreditCard input {
min-height: 45px!important;
font-size: 12px!important;
}
}
#media (max-width: 360px) {
#CheckoutCreditCard input {
font-size: 10px!important;
}
#add_payment_method #payment ul.payment_methods li input,
.woocommerce-cart #payment ul.payment_methods li input,
.woocommerce-checkout #payment ul.payment_methods li input {
margin: 0 .5em 0 0;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div id="CheckoutCreditCard" class="CC_container" ">
<div class="CC_input_group "">
<fieldset id="nmipay-cc-form" class="wc-credit-card-form wc-payment-form">
<input id="nmipay-card-number" class="nmipay-input-field input-text wc-credit-card-form-card-number" type="text" maxlength="20" autocomplete="off" placeholder="Card Number" name="nmipay-card-number" />
<input id="nmipay-card-expiry" class="nmipay-input-field input-text wc-credit-card-form-card-expiry" type="text" maxlength="7" autocomplete="off" placeholder="MM / YY" name="nmipay-card-expiry" />
<input id="nmipay-card-cvc" class="nmipay-input-field input-text wc-credit-card-form-card-cvc" type="text" autocomplete="off" maxlength="4" placeholder="CVC" name="nmipay-card-cvc" />
<div class="clear"></div>
</fieldset>
</div>
</div>

Customizing Increment Arrows on Input of Type Number Using CSS

I have an input of type number that is rendered using the following code:
<input class="quantity" id="id_form-0-quantity" min="0" name="form-0-quantity" value="1" type="number">
It looks like this:
I would like to turn it into something like this:
The second view is emulated using two separate buttons.
How could I style the arrows as described?
tl;dr:
Having been asked in private about the following setup quite a few times, I decided to add a demo for it (Bootstrap 4 + jQuery + Font Awesome input-group setup):
$('.btn-plus, .btn-minus').on('click', function(e) {
const isNegative = $(e.target).closest('.btn-minus').is('.btn-minus');
const input = $(e.target).closest('.input-group').find('input');
if (input.is('input')) {
input[0][isNegative ? 'stepDown' : 'stepUp']()
}
})
.inline-group {
max-width: 9rem;
padding: .5rem;
}
.inline-group .form-control {
text-align: right;
}
.form-control[type="number"]::-webkit-inner-spin-button,
.form-control[type="number"]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<div class="input-group inline-group">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary btn-minus">
<i class="fa fa-minus"></i>
</button>
</div>
<input class="form-control quantity" min="0" name="quantity" value="1" type="number">
<div class="input-group-append">
<button class="btn btn-outline-secondary btn-plus">
<i class="fa fa-plus"></i>
</button>
</div>
</div>
long (initial) answer:
The native input[type=number] controls are not style-able cross-browser. The easiest and safest way to achieve what you want cross-browser/cross-device is to hide them using:
input[type="number"] {
-webkit-appearance: textfield;
-moz-appearance: textfield;
appearance: textfield;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
}
...which allows you to use your custom buttons, which could be linked to execute the functions the spinners (arrows) would (.stepUp() and .stepDown()), provided you keep the input's type="number".
For example:
input[type="number"] {
-webkit-appearance: textfield;
-moz-appearance: textfield;
appearance: textfield;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
}
.number-input {
border: 2px solid #ddd;
display: inline-flex;
}
.number-input,
.number-input * {
box-sizing: border-box;
}
.number-input button {
outline:none;
-webkit-appearance: none;
background-color: transparent;
border: none;
align-items: center;
justify-content: center;
width: 3rem;
height: 3rem;
cursor: pointer;
margin: 0;
position: relative;
}
.number-input button:before,
.number-input button:after {
display: inline-block;
position: absolute;
content: '';
width: 1rem;
height: 2px;
background-color: #212121;
transform: translate(-50%, -50%);
}
.number-input button.plus:after {
transform: translate(-50%, -50%) rotate(90deg);
}
.number-input input[type=number] {
font-family: sans-serif;
max-width: 5rem;
padding: .5rem;
border: solid #ddd;
border-width: 0 2px;
font-size: 2rem;
height: 3rem;
font-weight: bold;
text-align: center;
}
<div class="number-input">
<button onclick="this.parentNode.querySelector('input[type=number]').stepDown()" ></button>
<input class="quantity" min="0" name="quantity" value="1" type="number">
<button onclick="this.parentNode.querySelector('input[type=number]').stepUp()" class="plus"></button>
</div>
Note: In order to change the input's value, one needs to find it. To provide flexibility, in the example above I grouped buttons and the <input> under a common parent and used that parent to find the <input> (choosing not to rely on their proximity or particular order in DOM). The above method will change any input[type=number] sibling to the buttons. If that's not convenient, one could use any other methods to find the input from the buttons:
by id: .querySelector('#some-id'):
<button onclick="this.parentNode.querySelector('#some-id').stepUp()"></button>
by className: .querySelector('.some-class'):
<button onclick="this.parentNode.querySelector('.some-class').stepUp()"></button>
Also note the above examples only search inside the .parentNode, not in the entire document, which is also possible:
i.e: onclick="document.getElementById('#some-id').stepUp()"
by proximity (previousElementSibling | nextElementSibling)
<button onclick="this.previousElementSibling.stepUp()"></button>
any other way to determine and find a particular input element in a DOM structure. For example, one could use third party libraries, such as jQuery:
<button onclick="$(this).prev()[0].stepUp()"></button>
An important note when using jQuery is that the stepUp() and stepDown() methods are placed on the DOM element, not on the jQuery wrapper. The DOM element is found inside the 0 property of the jQuery wrapper.
Note on preventDefault(). Clicking a <button> inside a <form> will trigger the form submission. Therefore, if used as above, inside forms, the onclick should also contain preventDefault();. Example:
<button onclick="$(this).prev()[0].stepUp();preventDefault()"></button>
However, if one would use <a> tags instead of <button>s, this is not necessary. Also, the prevention can be set globally for all form buttons with a small JavaScript snippet:
var buttons = document.querySelectorAll('form button:not([type="submit"])');
for (i = 0; i < buttons.length; i++) {
buttons[i].addEventListener('click', function(e) {
e.preventDefault();
});
}
... or, using jQuery:
$('form').on('click', 'button:not([type="submit"])', function(e){
e.preventDefault();
})
Number inputs can be stylized this way with the following script I recently found:
Demo.
This script is a super-light-weight (1.49kb uncompressed, 0.71kb compressed, 0.35kb gzipped), usable and reliable quantity input that replaces the horrible, fiddly little input buttons built in to the number input in the browser. It is written using ES6 modules, so will need to be transpiled for older browsers.
The author's repository is here.
Hope this helps ;)
Edit:
Alternatively, if you'd like to have up/down arrow buttons instead of plus/minus ones, there is another jQuery-based solution.
$(document).ready(function () {
jQuery('<div class="quantity-nav"><button class="quantity-button quantity-up"></button><button class="quantity-button quantity-down">&#xf107</button></div>').insertAfter('.quantity input');
jQuery('.quantity').each(function () {
var spinner = jQuery(this),
input = spinner.find('input[type="number"]'),
btnUp = spinner.find('.quantity-up'),
btnDown = spinner.find('.quantity-down'),
min = input.attr('min'),
max = input.attr('max');
btnUp.click(function () {
var oldValue = parseFloat(input.val());
if (oldValue >= max) {
var newVal = oldValue;
} else {
var newVal = oldValue + 1;
}
spinner.find("input").val(newVal);
spinner.find("input").trigger("change");
});
btnDown.click(function () {
var oldValue = parseFloat(input.val());
if (oldValue <= min) {
var newVal = oldValue;
} else {
var newVal = oldValue - 1;
}
spinner.find("input").val(newVal);
spinner.find("input").trigger("change");
});
});
});
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
min-width: 100vw;
background: #34495E;
font-size: 1rem;
}
.quantity {
position: relative;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type=number] {
-moz-appearance: textfield;
}
.quantity input {
width: 45px;
height: 42px;
line-height: 1.65;
float: left;
display: block;
padding: 0;
margin: 0;
padding-left: 20px;
border: none;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
font-size: 1rem;
border-radius: 4px;
}
.quantity input:focus {
outline: 0;
}
.quantity-nav {
float: left;
position: relative;
height: 42px;
}
.quantity-button {
position: relative;
cursor: pointer;
border: none;
border-left: 1px solid rgba(0, 0, 0, 0.08);
width: 21px;
text-align: center;
color: #333;
font-size: 13px;
font-family: "FontAwesome" !important;
line-height: 1.5;
padding: 0;
background: #FAFAFA;
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
.quantity-button:active {
background: #EAEAEA;
}
.quantity-button.quantity-up {
position: absolute;
height: 50%;
top: 0;
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
font-family: "FontAwesome";
border-radius: 0 4px 0 0;
line-height: 1.6
}
.quantity-button.quantity-down {
position: absolute;
bottom: 0;
height: 50%;
font-family: "FontAwesome";
border-radius: 0 0 4px 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="quantity">
<input type="number" min="1" max="9" step="1" value="1">
</div>
Here is another version, based on the answer of #tao, using font-awesome:
input[type="number"] {
-webkit-appearance: textfield;
-moz-appearance: textfield;
appearance: textfield;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
}
.number-input {
border: 2px solid #ddd;
display: inline-flex;
}
.number-input,
.number-input * {
box-sizing: border-box;
}
.number-input button {
outline:none;
-webkit-appearance: none;
background-color: transparent;
border: none;
align-items: center;
justify-content: center;
width: 3rem;
height: 3rem;
cursor: pointer;
margin: 0;
position: relative;
}
.number-input button:after {
display: inline-block;
position: absolute;
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: '\f077';
transform: translate(-50%, -50%) rotate(180deg);
}
.number-input button.plus:after {
transform: translate(-50%, -50%) rotate(0deg);
}
.number-input input[type=number] {
font-family: sans-serif;
max-width: 5rem;
padding: .5rem;
border: solid #ddd;
border-width: 0 2px;
font-size: 2rem;
height: 3rem;
font-weight: bold;
text-align: center;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" integrity="sha512-HK5fgLBL+xu6dm/Ii3z4xhlSUyZgTT9tuc/hSrtw6uzJOvgRr2a9jyxxT1ely+B+xFAmJKVSTbpM/CuL7qxO8w==" crossorigin="anonymous" />
<div class="number-input">
<button onclick="this.parentNode.querySelector('input[type=number]').stepDown()" class="minus"></button>
<input class="quantity" min="0" name="quantity" value="1" type="number">
<button onclick="this.parentNode.querySelector('input[type=number]').stepUp()" class="plus"></button>
</div>
You can easily convert first design with second one like this:
HTML
<div class="quantity">
<button class="btn minus1">-</button>
<input class="quantity" id="id_form-0-quantity" min="0" name="form-0-quantity" value="1" type="number">
<button class="btn add1">+</button>
CSS
.quantity{
display:flex;
width:160px;
}
/* it will support chrome and firefox */
.quantity input[type=number]::-webkit-inner-spin-button,
.quantity input[type=number]::-webkit-outer-spin-button{
-webkit-appearance:none;
}
.quantity input,.quantity button{
width:50px;
padding:.5em;
font-size:1.2rem;
text-align:center;
font-weight:900;
background:white;
border:1px solid #aaa;
}
.quantity input{
border-left:none;
border-right:none;
}
I found a nice solution. Just rotate the arrow keys and set the opacity to 0. (they are now in the right place, invisible but clickable) Then set an :after and :before element over these invisible buttons. These elements can then be styled as desired.
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
transform: rotate(90deg);
height: 80px;
opacity: 0;
}
.quantity-wrapper {
position: relative;
}
.quantity-wrapper:after {
content: "+";
position: absolute;
right: 5px;
height: 100%;
top: 8px;
pointer-events: none;
}
.quantity-wrapper:before {
content: "-";
position: absolute;
left: 5px;
height: 100%;
top: 8px;
}
<div class="quantity-wrapper">
<input class="quantity" id="id_form-0-quantity" min="0" name="form-0-quantity" value="1" type="number">
</div>
This code can help you .may be found [here also](Detecting number input spinner click
$.fn.spinInput = function (options) {
var settings = $.extend({
maximum: 1000,
minimum: 0,
value: 1,
onChange: null
}, options);
return this.each(function (index, item) {
var min = $(item).find('>*:first-child').first();
var max = $(item).find('>*:last-child').first();
var v_span = $(item).find('>*:nth-child(2)').find('span');
var v_input = $(item).find('>*:nth-child(2)').find('input');
var value = settings.value;
$(v_input).val(value);
$(v_span).text(value);
async function increment() {
value = Number.parseInt($(v_input).val());
if ((value - 1) > settings.maximum) return;
value++;
$(v_input).val(value);
$(v_span).text(value);
if (settings.onChange) settings.onChange(value);
}
async function desincrement() {
value = Number.parseInt($(v_input).val());
if ((value - 1) < settings.minimum) return;
value--
$(v_input).val(value);
$(v_span).text(value);
if (settings.onChange) settings.onChange(value);
}
var pressTimer;
function actionHandler(btn, fct, time = 100, ...args) {
function longHandler() {
pressTimer = window.setTimeout(function () {
fct(...args);
clearTimeout(pressTimer);
longHandler()
}, time);
}
$(btn).mouseup(function () {
clearTimeout(pressTimer);
}).mousedown(function () {
longHandler();
});
$(btn).click(function () {
fct(...args);
});
}
actionHandler(min, desincrement, 100);
actionHandler(max, increment, 100)
})
}
$('body').ready(function () {
$('.spin-input').spinInput({ value: 1, minimum: 1 });
});
:root {
--primary-dark-color: #F3283C;
--primary-light-color: #FF6978;
--success-dark-color: #32A071;
--sucess-light-color: #06E775;
--alert-light-color: #a42a23;
--alert-dark-color: #7a1f1a;
--secondary-dark-color: #666666;
--secondary-light-color: #A6A6A6;
--gold-dark-color: #FFA500;
--gold-light-color: #FFBD00;
--default-dark-color: #1E2C31;
--default-light-color: #E5E5E5;
}
.fx-row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.fx-colum {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.fx-colum.nowrap,
.fx-row.nowrap {
flex-wrap: nowrap;
}
.fx-row.fx-fill>*,
.fx-colum.fx-fill>* {
flex-grow: 1;
}
.spin-input {
border: 1px solid var(--secondary-light-color);
}
.spin-input>div:first-child {
cursor: pointer;
border-right: 1px solid var(--secondary-light-color);
}
.spin-input>div:first-child:active {
transform: translate3d(1px, 0px, 1px)
}
.spin-input>div:last-child {
flex: none;
border-left: 1px solid var(--secondary-light-color);
cursor: pointer;
}
.spin-input>div:last-child:active {
transform: translate3d(1px, 0px, 1px)
}
.icon {
font-weight: bold;
text-align: center;
vertical-align: middle;
padding: 12px;
font-size: 28px;
}
.icon.primary,
.icon.primary .ci {
color: var(--primary-dark-color);
}
.icon.reactive:hover .ci {
color: var(--primary-light-color);
}
.hidden {
display: none;
}
<script src="https://releases.jquery.com/git/jquery-3.x-git.min.js"></script>
<div class="spin-input nowrap fx-row fx-fill" >
<div class="icon reactive">
<span class="ci ci-minus">-</span>
</div>
<div class="icon">
<span>0</span>
<input type="text" class="hidden" value="0">
</div>
<div class="icon reactive">
<span class="ci ci-plus">+</span>
</div>
</div>
259)

It is possible to have 2 different font sizes in one input placeholder in css?

Is it possible to have 2 different font sizes in one input placeholder in CSS?
something like this design:
In regular html you can make it with span,:before,&:after and etc.
but in input you cant make all this things so i want to understand if its possible...
thanks
To apply different styles in the same placeholder is not possible.
What you can do however is either use pseudo elements or a div which behaves as a placeholder and hide/show it when the input is focussed.
This might help:
$("#input").keyup(function() {
if ($(this).val().length) {
$(this).next('.placeholder').hide();
} else {
$(this).next('.placeholder').show();
}
});
$(".placeholder").click(function() {
$(this).prev().focus();
});
.placeholder {
position: absolute;
margin: 7px 8px;
color: #A3A3A3;
cursor: auto;
font-size: 14px;
top: 7px;
}
.small {
font-size: 10px;
}
input {
padding: 5px;
font-size: 11pt;
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="input" type="text" />
<div class="placeholder">Email <span class="small">address</span>
</div>
CSS only Solution
.input-field {
position: relative;
display: inline-block;
}
.input-field > label {
position: absolute;
left: 0.5em;
top: 50%;
margin-top: -0.5em;
opacity: 1;
display: none;
}
.input-field > input[type=text]:placeholder-shown + label {
display: block;
}
.input-field > label > span {
letter-spacing: -2px;
}
.first-letter {
color: red;
font-size:100%;
}
.second-letter {
color: blue;
font-size:50%;
}
.third-letter {
color: orange;
font-size:75%;
}
.fourth-letter {
color: green;
font-size:100%;
}
.fifth-letter {
color: yellow;
font-size:25%;
}
<div class="input-field">
<input id="input-text-field" type="text" placeholder=" "></input>
<label for="input-text-field">
<span class="first-letter">H</span>
<span class="second-letter">E</span>
<span class="third-letter">L</span>
<span class="fourth-letter">L</span>
<span class="fifth-letter">O</span>
</label>
</div>
JS solution
addListenerMulti(document.getElementById('input-text-field'), 'focus keyup', blurme);
function blurme(e) {
var element = e.currentTarget;
element.classList[(element.value.length !== 0) ? "add" : "remove"]('hide-placeholder');
}
function addListenerMulti(el, s, fn) {
s.split(" ").forEach(function(e) {
return el.addEventListener(e, fn, false)
});
}
.input-field {
position: relative;
display: inline-block;
}
.input-field > label {
position: absolute;
left: 0.5em;
top: 50%;
margin-top: -0.5em;
}
.hide-placeholder + label {
display: none;
}
.input-field > label > span {
letter-spacing: -2px;
}
.first-letter {
color: red;
font-size:100%;
}
.second-letter {
color: blue;
font-size:100%;
}
.third-letter {
color: orange;
font-size:100%;
}
.fourth-letter {
color: green;
font-size:50%;
}
.fifth-letter {
color: black;
font-size:50%;
}
<div class="input-field">
<input id="input-text-field" type="text">
<label for="input-text-field">
<span class="first-letter">H</span>
<span class="second-letter">E</span>
<span class="third-letter">L</span>
<span class="fourth-letter">L</span>
<span class="fifth-letter">O</span>
</label>
</div>