CSS: Reset INPUT Element to Original Width - html

I don't think this is possible but I am going to ask it nonetheless, lets say I have the following HTML:
<div style="width: 500px;">
<input class="full" />
</div>
And the corresponding CSS:
input {
width: 100%;
}
.full {
display: inline;
float: left;
margin: 0 2%;
width: 96%
}
In this case my input element will have a width of 480px, this works fine for most of my needs but in some specific cases it doesn't, for instance:
<div style="width: 500px;">
<input name="day" size="2" />
<input name="month" size="2" />
<input name="year" size="4" />
</div>
This will make the browser render each input with a width of 500px (jsFiddle)...
Is there anyway to force the browser to rollback to the default style?

Just set width:auto to those inputs. This works with or without setting the size attribute (respects size if you have set it).
http://jsfiddle.net/Madmartigan/kQDpY/3/
BTW, float will automatically set the display type to block, your inline declaration for the div isn't doing anything so you don't need it.

Just override it with an !important selector:
input {
width: auto !important;
}
And a demo: http://jsfiddle.net/kQDpY/4/

width: auto;
Is this what you're after?
Basically I've set width:auto; to all inputs that define size attribute. Maybe this isn't the correct attribute but it shows how you can distinguish inputs between each other.
But basically you haven't told us what you'd like with these three inputs. Would you want them to occupy the whole width but should be 2:2:4 in size or is it just auto with as it seems we all did...

Related

Make two elements with dimensions inline

I am trying to make the two elements in the header, the pink section and the green section, be inline ( in one line and not wrapping to a new line as the green section is currently).
However, I can't use display:inline; as the items need to have a width.
How can I achieve both of these elements being inline and keep their widths?
Here is the page where the elements are: https://dl.dropboxusercontent.com/u/270523/help/new.html
The inline-block solution:
#logo {
width: [WIDTH1]%;
min-width: 225px;
background: pink;
}
#input{
width: [WIDTH2]%;
background: green;
}
#input,#logo {
display: inline-block;
height: 100%;
vertical-align:top;
}
Where [WIDTH1] + [WIDTH2] = 100%.
For this to work, you need to delete the whitespaces between the two elements.
So not like now:
<section id="logo"></section>
<section id="input">
<input id="searchInput" type="text" name="search" autocomplete="off">
</section>
But instead:
<section id="logo"></section><section id="input">
<input id="searchInput" type="text" name="search" autocomplete="off">
</section>
You've set the float to the #input section but not the #logo section.
#logo {
width:20%;
float: left;
}
Your section input is dropping because it is having extra width, make it around 77% then it will work for you.
#input{width:77%;}
first of all it is really nice You use html5 tags its good for You. In my opinion the easiest way is use a float for all of elements in header, but remember to clear:both parent tag.
Here is demo of modified your code: http://jsfiddle.net/bartekbielawa/WgtAP/

Default input element size

The input element by default is size="20" if this is not defined inline or a CSS style rule is attributed to it.
How do you make the default the actual size of the value? For other elements:
<div style="display: inline; width: auto;">
The box will only fit the width of it's content
</div>
width: auto is all you need. I cannot put a defined width since the value may be longer. For example:
<input id="short" type="text" value="1000" />
<input id="long" type="text" value=" Areally long name is in this input field." />
I want #short to be the size of 1000 (essentially size="4" + the padding) but the #long to be as long as needed. These inputs are coming in programatically so I can't simply put a short class on the one's I want short and a long class on the one's I want long. I would really just like it if I could put:
input { width: auto; }
Anyway to do this?
The input element by default is size="20"
This "default size" depends on the browser, the version and your OS.
It is not possible to do this in inline styles.
the best solution is to set width and padding so it adds up to 100%
input {
width: 98%;
padding: 1%;
}
then set it to absolute left and right 0
<fieldset>
<input type="text" />
</fieldset>
finally add this css
<style type="text/css">
fieldset {
position: relative;
}
input {
position: absolute;
left: 0;
right: 0;
}
</style>
"How do you make the default the actual size of the value? (...) I would really just like it if I could put: input { width: auto; }
Anyway to do this?"
In an Input HTML Element, width is controlled by its size attribute. This is a quick way I use to simulate { width: auto; }, and it is browsers dependance proof:
Angular:
<input type="text" [size]="element.value.length + 1" #element>
Pure Vanilla JavaScript:
<input type="text" oninput="this.size = this.value.length + 1">
Assuming you have each input on its own row in the form, you can set size attribute to the desired size but also add a css of:
input[type="text"] {
max-width: 100%;
}
This ensures that the field does not overflow the form. This approach gives a visual cue of how much data is expected for short fields (because they will be the right size) while putting a cap on long ones.

Auto extend width to text field

How to get the text field with auto extend based on the browser width (with pure css). For example if I scale the browser to minimum width also the text field should not jump to the second line.
I need exactly like how it is shown in this image
Not 100% sure it's the desired effect but for some browsers this might be what you're looking for:
html:
<p>
<label>Test</label>
<span><input></span>
</p>​
And css:
label{width:200px;float:left;}
span{display:block;width:100%;box-sizing:border-box;padding-left:200px;}
input{width:100%;box-sizing:border-box;}​
Example: http://jsfiddle.net/48fNt/ (works in at least chrome)
Maybe you also still need to play around with white-space:nowrap and a min-width.
You can't do it alone with CSS. Use
jQuery AutoResize Plugin
$('#myTextBox').autoResize({
onResize : function() {
//Do something on resize
},
animateCallback : function() {
//Do something after resize
},
animateDuration : 300,//Duration
extraSpace : 40//Extra Space
});
As far as I can know, you cannot do it with only CSS for inputs, but you can emulate this behaviour using a div with contenteditable attribute - demo http://dabblet.com/gist/3150040
HTML
<div contenteditable></div>
CSS
div {
min-width: 150px;
width: auto;
border: solid 1px #ccc;
display: inline-block;
}
there are more than one ways you can achieve this position
http://jsfiddle.net/rHqE7/4/
<div id="wrap">
<div id="name">Name</div>
<input type="text" name="fname" id="text" />
</div>​
#wrap{width:500px;overflow:auto;}​
#name{float:left;width:100px;font-size:16pt;padding:10px 5px;}
#text{float:left;min-width:300px;max-height:20px;border:1px solid black;padding:3px;}

HTML: How to center align a form

I have the following HTML code and I want to make my form aligned in center.
<form action="advsearcher.php" method="get">
Search this website:<input align="center" type="text" name="search" />
<input type="submit" value="Search"/>
</form>
How can I do that?
#Lucius and #zyrolasting have it right.
However, you will probably need to give the form a specified width for it to work properly.
form {
margin: 0 auto;
width:250px;
}
Just put some CSS into the stylesheet like this
form {
text-align: center;
}
then you're done!
Being form a block element, you can center-align it by setting its side margins to auto:
form { margin: 0 auto; }
EDIT:
As #moomoochoo correctly pointed out, this rule will only work if the block element (your form, in this case) has been assigned a specific width.
Also, this 'trick' will not work for floating elements.
This will have the field take 50% of the width and be centered and resized properly
{
width: 50%;
margin-left : 25%
}
May also use "vw" (view width) units instead of "%"
Use center:
<center><form></form></center>
This is just one method, though it's not advised.
Ancient Edit: Please do not do this. I am just saying it is a thing that exists.
Just move align="center" to the form tag.
<form align="center" action="advsearcher.php" method="get">
Search this website:<input type="text" name="search" />
<input type="submit" value="Search"/>
</form>
The last two lines are important to align in center:
.f01 {
background-color: rgb(16, 216, 252);
padding: 100px;
text-align: left;
margin: auto;
display: table;
}
#form{
position:fixed;
top:50%;
left:50%;
width:250px;
}
You can adjust top & left depending on form size.
Try this :
Set the width of the form as 20% by:
width : 20%;
now if the entire canvas is 100 %, the centre is at 50%. So to align the centre of the form at the centre, 50-(20/2) = 40.
therefore set your left margin as 40% by doing this :
left : 40%;
simple way:Add a "center" tag before the form tag
<center><form></form></center>
does work in most cases like The Wobbuffet mentioned above...

Text input width max and input submit on one line

I make a small chat. There was a problem with CSS, because I'm more a programmer than a layout designer.
HTML:
<div class="chat_input_box">
<input type="text" class="chat_input_text" name="message">
<input type="submit" value="Отправить" class="chat_submit_button">
</div>
CSS:
.chat_input_box {
width: 100%;
}
.chat_input_text {
width: 83%;
}
.chat_submit_button {
margin-right: 0px;
}
The problem is that it is not goes to set the width of the text field maximum without hardcode (83% for example).
try to put button and input filed into two different divs. Give button div CSS parameter "float: right; width: someAmount px;"
Not really what you asked for, but as close as possible: http://jsfiddle.net/TQvg8/