input and button, same css, different heights - html

I am having same css properties, yet the button and input fields are different fields
.input-con {
position: relative;
}
.input-con>* {
line-height: 1;
display: inline-block;
vertical-align: middle;
padding: 10px;
border: 0;
background-color: #ddd;
color: #444;
outline: 0;
cursor: pointer;
font-size: 15px;
box-sizing: border-box;
}
<div class="input-con">
<input type="text" />
<button>Search</button>
</div>
pen - https://codepen.io/digitalzoomstudio/pen/LOoVYK
How could I achieve same heights without forcing height property ?

You can use flex box , just add display:flex; on the parent (input-con)
.input-con {
position: relative;
display:flex;
}
.input-con>* {
line-height: 1;
display: inline-block;
vertical-align: middle;
padding: 10px;
border: 0;
background-color: #ddd;
color: #444;
outline: 0;
cursor: pointer;
font-size: 15px;
box-sizing: border-box;
margin-right:2px;
}
<div class="input-con">
<input type="text" />
<button>Search</button>
</div>

The reason you are seeing a discrepancy in the height is due - I think - to the font property, which includes shorthand for font-weight, font-size and font-family.
If you explicitly override this property for both input and button the height will match up.
.input-con {
position: relative;
}
.input-con>* {
line-height: 1;
display: inline-block;
vertical-align: middle;
padding: 10px;
border: 0;
background-color: #ddd;
color: #444;
outline: 0;
cursor: pointer;
font-size: 15px;
box-sizing: border-box;
}
input,
button {
font: 400 15px Arial !important;
}
<div class="input-con">
<input type="text" />
<button>Search</button>
</div>
updated as per comment
It will not work to declare font-weight, font-size and font-family separately, as this does not override the font shorthand completely.
The full shorthand is:
font: font-style font-variant font-weight font-size/line-height font-family;
Only if each of these properties is declared will the font property be overridden.
Note that font contains three separate properties for font-variant (ligatures, caps and numeric) - it seems that using font-variant is sufficient.
demo
.input-con {
position: relative;
}
.input-con>* {
/* override all properties of the 'font' shorthand */
font-style: normal;
font-variant: normal;
font-weight: 400;
font-size: 18px;
line-height: normal;
font-family: Arial, sans-serif;
display: inline-block;
vertical-align: middle;
padding: 10px;
border: 0;
background-color: #ddd;
color: #444;
outline: 0;
cursor: pointer;
box-sizing: border-box;
}
<div class="input-con">
<input type="text" />
<button>Search</button>
</div>

You added line-height: 1; which makes difference
.input-con {
position: relative;
}
.input-con>* {
/*line-height: 1;*/
display: inline-block;
vertical-align: middle;
padding: 10px;
border: 0;
background-color: #ddd;
color: #444;
outline: 0;
cursor: pointer;
font-size: 15px;
box-sizing: border-box;
}
<div class="input-con">
<input type="text" />
<button>Search</button>
<input type="text" />
</div>

Just add display:flex like this
.input-con {
position: relative;
display:flex;
}
Learn more about flex

Yes indeed Flexbox is the way to go, but if you're curious as why you're getting this behavior CSS Tricks has a good article https://css-tricks.com/fighting-the-space-between-inline-block-elements/

Try with this it may help
.input-con {
position: relative;
}
.input-con{
position:relative;
>*{
vertical-align:middle;
padding: 10px;
border:0;
background-color: #ddd;
color: #444;
outline:0;
cursor:pointer;
font-size: 15px;
}
}

Related

css can't change checkbox background color

I'm learning css and html, I'm validating a registration form, I have the user terms checkbox but I can't change the background color:
This is the html code where I create the checkbox and the label:
<div class="checkbox-wrap checkbox-primary" id="checkboxdiv" name="checkboxdiv">
<input class="checkbox" type="checkbox" value="0" name="termsNewUser" id="termsNewUser">
<label class="checkbox-wrap checkbox-primary" for="termsNewUser" id="termsNewUserL" name="termsNewUserL">I do accept the <u>Terms and Conditions</u> of your site.
</label>
</div>
I tried some solutions like:
input[type="checkbox"] {
-webkit-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
accent-color: #9d3039;
}
And:
input[type=checkbox] {
transform: scale(1.5);
}
input[type=checkbox] {
width: 30px;
height: 30px;
margin-right: 8px;
cursor: pointer;
font-size: 17px;
visibility: hidden;
}
input[type=checkbox]:after,
input[type=checkbox]::after {
content: " ";
background-color: #fff;
display: inline-block;
margin-left: 10px;
padding-bottom: 5px;
color: #00BFF0;
width: 22px;
height: 25px;
visibility: visible;
border: 1px solid #00BFF0;
padding-left: 3px;
border-radius: 5px;
}
input[type=checkbox]:checked:after,
input[type=checkbox]:checked::after {
content: "\2714";
padding: -5px;
font-weight: bold;
}
I tried also to create a custom class and in the style.css set the accent there but nothing.
When you simply make a global definition like the one below, this color should change,
:root {
accent-color: red;
}
In your case, this change stays in the background since you have given the checkbox element visible hidden.
input[type=checkbox]:checked:after,
input[type=checkbox]:checked::after {
content: "\2714";
padding: -5px;
font-weight: bold;
background-color: red;
}
so in the checked state you can change the background color directly to get the same look.
demo https://jsfiddle.net/rjzw10cv/1/
ahh I remember having this issue. Here it is. Just change the background color and color to anything you'd like and you should be set. This can be done with any input type.
input[type="checkbox"]:checked+label:before {
background: #3d404e;
color: #F00;
content: "\2713";
text-align: center;
}
so your html code would be
<div class="checkbox-wrap checkbox-primary" id="checkboxdiv" name="checkboxdiv">
<input class="checkbox" type="checkbox" value="0" name="termsNewUser" id="termsNewUser">
<label class="checkbox-wrap checkbox-primary" for="termsNewUser" id="termsNewUserL" name="termsNewUserL">I do accept the <u>Terms and Conditions</u> of your site.
</label>
</div>
and your full css would be below, I added a margin-right:20px as to hide the large space behind the custom checkbox elements.
p {
margin: 5px 0;
padding: 0;
}
input[type="checkbox"] {
margin-right: -20px;
cursor: pointer;
font-size: 17px;
visibility: hidden;
}
label {
cursor: pointer;
}
/* EDIT THE BACKGROUND VALUE FOR CUSTOM CHECKBOX bg COLOR FOR NOT CHECKED */
input[type="checkbox"]+label:before {
border: 1px solid #7f83a2;
content: "\00a0";
display: inline-block;
background: #000;
font: 16px/1em sans-serif;
height: 16px;
margin: 0 .25em 0 0;
padding: 0;
vertical-align: top;
width: 16px;
}
/* EDIT THE BACKGROUND VALUE FOR CUSTOM CHECKBOX bg COLOR FOR CHECKED, CHANGE COLOR TO CHANGE CHECK MARK COLOR */
input[type="checkbox"]:checked+label:before {
background: #3d404e;
color: #ff0000;
content: "\2713";
text-align: center;
}
input[type="checkbox"]:checked+label:after {
font-weight: bold;
}
Here is a snippet:
p {
margin: 5px 0;
padding: 0;
}
input[type="checkbox"] {
margin-right: -20px;
cursor: pointer;
font-size: 17px;
visibility: hidden;
}
label {
cursor: pointer;
}
/* EDIT THE BACKGROUND VALUE FOR CUSTOM CHECKBOX bg COLOR FOR NOT CHECKED */
input[type="checkbox"]+label:before {
border: 1px solid #7f83a2;
content: "\00a0";
display: inline-block;
background: #000;
font: 16px/1em sans-serif;
height: 16px;
margin: 0 .25em 0 0;
padding: 0;
vertical-align: top;
width: 16px;
}
/* EDIT THE BACKGROUND VALUE FOR CUSTOM CHECKBOX bg COLOR FOR CHECKED, CHANGE COLOR TO CHANGE CHECK MARK COLOR */
input[type="checkbox"]:checked+label:before {
background: #3d404e;
color: #ff0000;
content: "\2713";
text-align: center;
}
input[type="checkbox"]:checked+label:after {
font-weight: bold;
}
<div class="checkbox-wrap checkbox-primary" id="checkboxdiv" name="checkboxdiv">
<input class="checkbox" type="checkbox" value="0" name="termsNewUser" id="termsNewUser">
<label class="checkbox-wrap checkbox-primary" for="termsNewUser" id="termsNewUserL" name="termsNewUserL">I do accept the <u>Terms and Conditions</u> of your site.
</label>
</div>

Can't find a way to correct my input text box

So I have a little input box where I only want to accept numbers and I have the looks and everything fine but when I click on it the box draws another box + up and down arrows. Want to get rid of both. Also how can I add a little icon to the begging of it like in the first image.
I want this when clicking inside the box + adding the little search icon
But I get this:
html:
<div class="GeolocationInput os-animation" data-os-animation="zoomInUp" data-os-animation-delay="1.5s">
<div style="width: 100%;">
<form class="GeolocationInput-form ">
<div>
<input type="number" class="GeolocationInput-input" placeholder="Escribe tu Codigo Postal..." >
</div>
<div>
<button class="GeolocationInput-button" disabled="">Continuar</button>
</div>
</form>
</div>
</div>
CSS:
.GeolocationInput {
max-width: 700px;
margin: 0 auto;
text-align: center;
-webkit-font-smoothing: antialiased;
}
.GeolocationInput .GeolocationInput-form {
width: 274px;
margin: 10px auto 0;
}
.GeolocationInput .GeolocationInput-input {
width: 274px;
}
.GeolocationInput-input {
box-sizing: border-box;
width: 90%;
border: 1px solid #aebcce;
border-radius: 100px;
padding: 15px 40px 10px 42px;
margin: 0 0 15px;
font-size: 16px;
font-family: proxima-nova,Helvetica Neue,Helvetica,Avenir,Lucida Grande,Arial,sans-serif;
font-weight: 300;
}
.GeolocationInput-button {
background: #635bd4;
max-width: 275px;
width: 90%;
color: #fff;
cursor: pointer;
font-size: 16px;
padding: 16px 32px;
text-decoration: none;
white-space: nowrap;
border-radius: 100px;
border: none;
font-family: proxima-nova,Helvetica Neue,Helvetica,Avenir,Lucida Grande,Arial,sans-serif;
font-weight: 500;
text-align: center;
}
http://jsfiddle.net/zhpmahnq/192/
You can remove the border with:
.GeolocationInput-input:focus {
outline: none;
}
The arrows are a little harder to remove, and you need different rules for different browsers.
For Webkit browsers (like Chrome), you need:
.GeolocationInput-input::-webkit-outer-spin-button,
.GeolocationInput-input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
For Firefox, you need:
.GeolocationInput-input {
-moz-appearance: textfield;
}
All of these have been added to the following example:
.GeolocationInput {
max-width: 700px;
margin: 0 auto;
text-align: center;
-webkit-font-smoothing: antialiased;
}
.GeolocationInput .GeolocationInput-form {
width: 274px;
margin: 10px auto 0;
}
.GeolocationInput .GeolocationInput-input {
width: 274px;
}
.GeolocationInput-input {
box-sizing: border-box;
width: 90%;
border: 1px solid #aebcce;
border-radius: 100px;
padding: 15px 40px 10px 42px;
margin: 0 0 15px;
font-size: 16px;
font-family: proxima-nova,Helvetica Neue,Helvetica,Avenir,Lucida Grande,Arial,sans-serif;
font-weight: 300;
-moz-appearance: textfield;
}
.GeolocationInput-input:focus {
outline: none;
}
.GeolocationInput-input::-webkit-outer-spin-button,
.GeolocationInput-input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
.GeolocationInput-input::-webkit-outer-spin-button,
.GeolocationInput-input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
.GeolocationInput-button {
background: #635bd4;
max-width: 275px;
width: 90%;
color: #fff;
cursor: pointer;
font-size: 16px;
padding: 16px 32px;
text-decoration: none;
white-space: nowrap;
border-radius: 100px;
border: none;
font-family: proxima-nova,Helvetica Neue,Helvetica,Avenir,Lucida Grande,Arial,sans-serif;
font-weight: 500;
text-align: center;
}
<div class="GeolocationInput os-animation" data-os-animation="zoomInUp" data-os-animation-delay="1.5s">
<div style="width: 100%;">
<form class="GeolocationInput-form ">
<div>
<input type="number" class="GeolocationInput-input" placeholder="Escribe tu Codigo Postal..." >
</div>
<div>
<button class="GeolocationInput-button" disabled="">Continuar</button>
</div>
</form>
</div>
</div>
Hope this helps! :)

Unchecking a check from an emulated checkbox

I'd like to know how to modify this code to handle unchecking from an emulated checkbox.
First, here's the original input html:
<input type="radio" name="rf538" id="rf538" class="page_checkbox">
And here is the input css for class page_checkbox:
.page_checkbox {
display: none;
}
After the input html, I have this:
<label for="rf538"><span></span>Pleasures</label>
Here is my css code for the span inside the label:
.page_checkbox+label span {
display: inline-block;
width: 18px;
height: 18px;
margin: -2px 8px 0px 0px;
background-color: #ffffff;
vertical-align: middle;
cursor: pointer;
border-radius: 1px;
}
Finally, here is the css code that creates the checkbox and the check:
.page_checkbox:checked+label span:before {
position: relative;
left: 3px;
top: 2px;
content: '\002714';
color: #f06000;
font: 16px/16px Arial, Helvetica, Sans-serif;
}
You can see that there is a CSS for having a checked state but I do not know how to handle for unchecking the checked span box. I imagine theres some javascript involved?
Since you can't uncheck a radio button without JavaScript or a reset button, what you seem to be after is a checkbox instead, so change the radio button to a checkbox and it works.
.page_checkbox {
display: none;
}
.page_checkbox+label span {
display: inline-block;
width: 18px;
height: 18px;
margin: -2px 8px 0px 0px;
background-color: #ffffff;
vertical-align: middle;
cursor: pointer;
border-radius: 1px;
}
.page_checkbox:checked+label span:before {
position: relative;
left: 3px;
top: 2px;
content: '\002714';
color: #f06000;
font: 16px/16px Arial, Helvetica, Sans-serif;
}
<input type="checkbox" name="rf538" id="rf538" class="page_checkbox">
<label for="rf538"><span></span>Pleasures</label>

Place dollar symbol inside a text input

I want to keep dollar symbol at beginning of text box. I am able to achieve this using the below code.
It works find in chrome and IE. The dollar symbol goes and sits next to label in firefox. How do i fix this problem? And for aligning the dollar symbol inline with text i use top 2px. Is there a way to better the css code.
.input-symbol-dollar:after {
color: #37424a !important;
content: "$";
font-size: 16px !important;
font-weight: 400;
left: 10px;
position: absolute;
top: 2px;
}
.input-symbol-dollar {
position: relative;
}
.abc-input {
border: 2px solid #c9c9c9;
box-shadow: none;
color: #6b6f72;
font-size: 0.9375rem;
text-transform: none;
width: 100%;
color: #37424a !important;
font-family: "Roboto Regular", sans-serif;
font-size: 16px !important;
font-weight: 400;
height: 42px !important;
padding-left: 17px !important;
display: inline-block !important;
}
label {
color: #37424a;
display: inline-block;
font-family: "Roboto Bold", sans-serif;
font-size: 15px;
font-weight: 700;
margin-bottom: 8px;
}
<label for="abcInput" class="abc-label">lable filed </label>
<span class="input-symbol-dollar">
<input type="text" id="abcInput" tabindex="0" name="abc" class="abc-input " placeholder="0.00"></span>
https://jsfiddle.net/8jdek3zt/5/
It looks like there's a lot of unnecessary code in your example.
Here's a simplified version that works on Chrome, Firefox and IE (not tested in Safari).
span {
display: inline-block;
position: relative;
}
input {
border: 2px solid #c9c9c9;
box-shadow: none;
font-family: "Roboto Regular", sans-serif;
font-size: 1.5em;
height: 42px;
padding-left: 20px;
}
span::before {
content: "$";
font-family: "Roboto Regular", sans-serif;
font-size: 1.5em;
position: absolute;
left: 5px;
top: 50%;
transform: translateY(-50%);
}
<span>
<input placeholder="0.00">
</span>
Here's an explanation of the vertical centering method for the pseudo-element:
Element will not stay centered, especially when re-sizing screen
The reason why this is happening is because the span is an inline element, so it's positioning isn't calculated as you are expecting it to be. The easiest solution would be to set display: block on the <span class="input-symbol-dollar">
As for positioning it in a cleaner way, you could consider making the symbol display block as well, with a height 100% of the input and set the line-height equal to the input height. I've updated your fiddle but the relevant code is below:
https://jsfiddle.net/chzk1qgm/1/
.input-symbol-dollar {
position: relative;
display: block;
}
.input-symbol-dollar:after {
color: #37424a !important;
content: "$";
font-size: 16px !important;
font-weight: 400;
position: absolute;
display: block;
height: 100%;
top: 0;
left: 10px;
line-height: 46px; // height of input + 4px for input border
}
Alternatively, you could just change the span to a div, as a div is a block level element by default. The rest of the styles would remain the same though.
try putting span in div.
<label for="abcInput" class="abc-label">lable filed </label>
<div>
<span class="input-symbol-dollar">
<input type="text" id="abcInput" tabindex="0" name="abc" class="abc-input " placeholder="0.000">
</span>
</div>
.custom-text{
border: 2px solid #DDD;
width: 100%;
padding: 5px;
}
<div class="custom-text">
<span>$</span>
<input style="border: none;"/>
</div>

Aligning text beside a radio/checkbox in HTML

There is some padding from the top to the Keep me logged in text.
How can I remove the padding and make it look like this ?
HTML:
<div class="login-radio">
<input type="radio">Keep me logged in
</div>
CSS:
.login-radio {
font-size: 12px;
position: fixed;
left:60%;
top: 7%;
color: white;
font-family: arial;
}
Try this:
HTML:
<div>
<div class="email">
<input type="email" />
</div>
<div class="checkbox">
<input type="checkbox" />
<span>Keep me logged in</span>
</div>
</div>
CSS:
.email input {
float: left;
margin-top: 5px;
margin-left: 5px;
font-family: arial, sans-serif;
font-size: 12px;
outline: none;
}
.checkbox input {
float: left;
margin-top: 10px;
margin-left: 5px;
color: #000;
clear: both;
}
.checkbox span {
float: left;
margin-top: 7px;
margin-left: 2px;
font-family: arial, sans-serif;
}
Here's the fiddle.
Regards, Milan.
Try to use this:
HTML
<div class="login-radio radio">
<input type="radio" class="radio">
<label>Keep me logged in </label>
</div>
CSS
.login-radio, .login-checkbox, .radio, .checkbox {
display: block;
min-height: 20px;
margin-top: 10px;
margin-bottom: 0px;
padding: 0px;
margin-left: -20px;
}
input[type=checkbox] {
box-sizing: border-box;
margin: 4px 0 0;
line-height: normal;
}
.radio label, .checkbox label {
display: inline;
cursor: pointer;
}
Is this is what you want exactly the position of your radio button to be or something else
.login-radio input {
vertical-align:top;margin-top:1px;
}
http://jsfiddle.net/we9x6k3j/1/
3 steps that will fix your problem:
Remove the default margin and padding that the browser applies to the <input> by default.
Wrap the text in a <label>.
Apply vertical-align: middle to the <input> and the <label>.
Working Code Snippet:
.login-radio {
font-size: 12px;
position: fixed;
left:60%;
top: 7%;
color: black;
font-family: arial;
}
input{
margin: 0px;
padding: 0px;
}
input, label{
vertical-align: middle;
}
<div class="login-radio">
<input type="radio">
<label>Keep me logged in</label> <!-- wrap the text in a label -->
</div>
FIDDLE HERE
CSS:
.login{
width: 200px;
height:80px;
background-color: brown;
color: white;
}
.loginInput{
margin-left: 3%;
margin-top: 1%;
}
.loginRadio input{
margin-left: 3%;
vertical-align: top;
}
Key change is the vertical alignment of loginRadio input.