CSS box-sizing messing with form heights - css

I've uploaded this question a while ago but it ended up giving me the tumbleweed badge so I'm trying again.
I'm going through Michael Hartl's railstutorial right now and I've encountered a problem where box-sizing property is interfering with form heights as shown in pictures below.
#mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
height: auto;
margin-bottom: 15px;
#include box_sizing; <--- this line here is causing issues
}
(box-sizing property in effect)
(box-sizing property not in effect)
Notice how much smaller forms are when box-sizing property is in effect? You can't really view full letters because the height is so low. I've tried to change the height property under input, textarea, ..etc. but it seems like my code is being overridden by Bootstrap. If you have any idea how to make the forms bigger (greater height) I would really appreciate it.

box-sizing: border-box changes the box model so padding is taken out from the height, rather than adding to it.
So this block:
div {
box-sizing: content-box; // default
height: 2em;
padding: .25em;
}
Will be 2.5em tall, and this block:
div {
box-sizing: border-box;
height: 2em;
padding: .25em;
}
will be 2em tall, with .5em of spacing partitioned for the padding.
The other issue is how bootstrap defines the height of inputs:
input[type="text"], ...other selectors..,
.uneditable-input {
display: inline-block;
height: 20px;
...
}
The reason defining a height wasn't working, is because input[type="text"] is more specific than input, and therefore the bootstrap declaration was overriding yours.
To solve the problem you are having with the inputs, define a height and use a more specific selector:
input[type="text"], textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
height: 2em;
margin-bottom: 15px;
#include box_sizing;
}
Demo

Related

Entered text causing textarea to expand outside of div after form submit

I have a form that is driving me nuts. The form contains several textareas as input fields. When copying and pasting or just typing the data into the textarea everything is fine. However, when I submit the form and it re-displays, the textarea has now expanded, outside of its container div, to accommodate any text that has no spaces in it and overflows the width. Should it not wrap like it did when first entered? And if so, how do I get it to stop expanding the textarea?
Examples:
Before from submit:
After form submit:
#incexfrm {
width: 675px;
background-color: #d9d9d9;
border: 2px solid #000;
}
.category textarea {
height: 100%;
width: 99%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
The #incexfrm id is the CSS for the container. The .category class contains the CSS for the various textareas on the form.
Any help would be appreciated. Thank you!
As per your question, I have suggested you to use the following code-
Here your textarea must be in category class
#incexfrm {
width: 675px;
background-color: #d9d9d9;
border: 2px solid black;
}
.category {
width: 100%;
}
.category textarea {
height: 100%;
width: 99%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

Why cannot I view input text in the Firefox browser?

When I go to http://128.199.58.229/landingpage/ in Chrome and Safari I can read the placeholder text and see the text I input.
In Firefox I don't see any input text.
When I change the padding..
.form-control {
color: #A1A1A1;
font-size: 16px;
padding: 0;
}
I can see the text.. but of course the padding is terrible now. Any fix for this?
Thanks
Change the .form-control to box-sizing: content-box and provide a smaller padding value.
Like this:
.form-control {
color: #A1A1A1;
font-size: 16px;
padding: 10px;
box-sizing: content-box;
}
Currently, the box-sizing: border-box property is combining the padding with the height and creating unexpected results in Firefox.
box-sizing is explained nicely over here on CSS Tricks
Instead of disturbing padding change the height to 54px
.form-control {
color: #A1A1A1;
font-size: 16px;
height: 54px;
}
Problem was height,Your padding is too much
CSS
.form-control
{
height:100%;
padding: 10px;
}

How to fix input paddig in HTML5

I have a problem with padding in HTML5. I'm using this code:
input[type="password"] {
border: 1px solid #CECECE;
border-radius: 0 0 3px 3px;
padding: 7px;
font-size: 1em;
outline: none;
width: 100%;
margin: 0px;}
I use inputs in div, which has padding 10px.
And when I'm testing code the width of input is not right, look at this pic:
How to solve this problem? I want to have padding 10px in any window size.
Add this CSS :
input {
-moz-box-sizing:border-box;
-webkit-box-sizing: border-box;
box-sizing:border-box;
}
This property will include padding and border to the width/height of inputs so they won't overflow anymore.
Use:
box-sizing:border-box;
-moz-box-sizing:border-box;
in your css file.
input[type="password"] {
border: 1px solid #CECECE;
border-radius: 0 0 3px 3px;
padding: 7px;
font-size: 1em;
outline: none;
width: 100%;
margin: 0px;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
/* apply a natural box layout model to all elements */
*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
http://fiddle.jshell.net/yTM9U/2/
You need to set the CSS style margin-right for the input.
input {
margin-right: 10px;
}
Padding is a cushioning/space inside the element. To push an element away from
surrounding elements internal cushioning/padding-space cannot help. Margin needs
to be set for those purposes...
But in your case, r/l to the form width, inputs are already very wide (100%). So, you need to decrease the width of the inputs. Try
input {
width: 90%;
max-width: 90%;
}

In-Field Labels Don't Line Up With Input Text

I'm using Viget's In-Field Labels plugin on a form, but even though the label and input have the same font size, same line height, same height, same padding, same everything, the input and label text does not line up. The input text is one pixel lower than the label text.
HTML:
<div class="fieldgroup">
<label for="name">Name</label>
<input type="text" id="name" name="name">
</div><!--/.fieldgroup-->
CSS:
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
font-family: Arial;
}
.fieldgroup {
position: relative;
}
input[type='text'],
label {
padding: 5px;
font-size: 16px;
line-height: 16px;
margin: 0;
height: 30px;
color: #fff;
display: block;
}
input[type='text'] {
border: none;
background: green;
}
The plugin sets the label's position to absolute and the top and left properties to 0.
Here's a fiddle.
What am I missing here?
It's possible to do this using almost 100% CSS and avoid all the layout flow issues caused by position: absolute;
jsFiddle demo
The trick is to wrap the LABEL around the text and INPUT element. Put the text inside of an element that can be given display: inline-block; margin-right: -100%;. This puts the text directly under the INPUT, which is given a transparent background so the text is visible through the INPUT.
Some Javascript is necessary to make the INPUT background opaque when the field has user input. There's no way around this at the moment… CSS can't "detect" a non-empty INPUT element.
http://jsfiddle.net/d8Apy/12/
Just size your labels & input via line-height. so text-overlap each others since they'll be sitting on same line-height
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
font-family: Arial;
}
.fieldgroup {
position: relative;
}
input[type='text'],
label {
padding: 5px;
margin: 0;
line-height:16px;
Font-size:16px;
color: #fff;
display: block;border:1px solid transparent
}
input[type='text'] {
border: none;
background: green;
}
I fixed the issue by tweaking one of the CSS rules:
input[type='text'], label {
padding: 5px;
margin: 0;
font-size: 1em;
line-height: 30px;
height: 30px;
color: #fff;
display: block;
}
The trick is to set the container height to be the same as the line-height.
You can see the effect at: http://jsfiddle.net/audetwebdesign/d8Apy/7/
Why this works???
My guess is that browsers compute the height of the anonymous line boxes differently between input and label elements. At least in FireFox, setting the line-height seems to do the trick.
I don't recall ever reading anything in the CSS3 spec related to these details.
Note - Cross-Browser Effects
I tested this in a few browsers and I discovered that if you set both height and line-height and use box-sizing, you get cross-browser issues. However, if you use line-height and box-sizing, the results are consistent. I have not tested with borders.

Michael Hartl Rails Tutorial - CSS not rendering properly

I already finished the tutorial but I'm having a slight issue with the CSS rendering since section 7 where you make the signup form. This is what I'm getting:
And this is what it's supposed to look like:
And this is the relevant CSS:
#mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
padding: 10px;
height: auto;
margin-bottom: 15px;
#include box_sizing;
}
Was wondering if anyone else had the same issue?
The difference is probably with the default height of an input in Chrome vs FireFox (Hartl's browser).
The CSS declaration height:auto; lets the browser calculate the default height.
I had the same issue with Chrome, and although I don't know if it's a good solution, I got the expected results by getting rid of the #include box_sizing; comment:
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
padding: 10px;
height: auto;
margin-bottom: 15px;
// #include box_sizing;
}
Based upon the Handy Sass Mixins by Jake Bresnehan at http://web-design-weekly.com/blog/2013/05/12/handy-sass-mixins and the section on Box Sizing, I was able to change the mixin block and the "include" line and get things working with the following situations:
#mixin box_sizing {
-moz-box-sizing: $box-model;
-webkit-box-sizing: $box-model;
box-sizing: $box-model;
}
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
#include box_sizing(border-box);
}
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
#include box_sizing(border-box);
}
input {
height: auto !important;
}
which is also referencing the Michael Hartl, Ruby on Rails Tutorial, Ch. 7 at http://ruby.railstutorial.org/chapters/sign-up#top

Resources