Add padding to HTML text input field - html

I want to add some space to the right of an <input type="text" /> so that there's some empty space on the right of the field.
So, instead of , I'd get .
So, same behavior just some empty space to the right.
I've tried using padding-right, but that doesn't seem to do anything.
Is there a way to do this (or fake it)?

You can provide padding to an input like this:
HTML:
<input type=text id=firstname />
CSS:
input {
width: 250px;
padding: 5px;
}
however I would also add:
input {
width: 250px;
padding: 5px;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
}
Box sizing makes the input width stay at 250px rather than increase to 260px due to the padding.
For reference.

padding-right works for me in Firefox/Chrome on Windows but not in IE. Welcome to the wonderful world of IE standards non-compliance.
See: http://jsfiddle.net/SfPju/466/
HTML
<input type="text" class="foo" value="abcdefghijklmnopqrstuvwxyz"/>
CSS
.foo
{
padding-right: 20px;
}

padding-right should work. Example linked.
http://jsfiddle.net/8Ged8/

HTML
<div class="FieldElement"><input /></div>
<div class="searchIcon"><input type="submit" /></div>
For Other Browsers:
.FieldElement input {
width: 413px;
border:1px solid #ccc;
padding: 0 2.5em 0 0.5em;
}
.searchIcon
{
background: url(searchicon-image-path) no-repeat;
width: 17px;
height: 17px;
text-indent: -999em;
display: inline-block;
left: 432px;
top: 9px;
}
For IE:
.FieldElement input {
width: 380px;
border:0;
}
.FieldElement {
border:1px solid #ccc;
width: 455px;
}
.searchIcon
{
background: url(searchicon-image-path) no-repeat;
width: 17px;
height: 17px;
text-indent: -999em;
display: inline-block;
left: 432px;
top: 9px;
}

you can solve this, taking the input tag inside a div,
then put the padding property on div tag. This work's for me...
Like this:
<div class="paded">
<input type="text" />
</div>
and css:
.paded{
padding-right: 20px;
}

<input class="form-control search-query input_style" placeholder="Search…" name="" title="Search for:" type="text">
.input_style
{
padding-left:20px;
}

Related

Decorate input field with textarea-like style

Maybe it's a strange question, but is it possible to decorate the input field bottom-right corner to have these two narrow lines, which are default in the textarea field? So it's only about the decoration, no need for the same functionality.
Pen: https://codepen.io/anon/pen/wxqpXK
input {
border-top: none;
border-left: none;
border-right: none;
}
<input type="text" placeholder="Input text">
<textarea name="" id="" cols="30" rows="10"></textarea>
.resizable-input {
/* make resizable */
overflow-x: hidden;
resize: horizontal;
display: inline-block;
/* no extra spaces */
padding: 0;
margin: 0;
white-space: nowrap;
/* default widths */
width: 10em;
min-width: 2em;
max-width: 30em;
}
/* let <input> assume the size of the wrapper */
.resizable-input > input {
width: 100%;
box-sizing: border-box;
margin: 0;
}
/* add a visible handle */
.resizable-input > span {
display: inline-block;
vertical-align: bottom;
margin-left: -16px;
width: 16px;
height: 16px;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAJUlEQVR4AcXJRwEAIBAAIPuXxgiOW3xZYzi1Q3Nqh+bUDk1yD9sQaUG/4ehuEAAAAABJRU5ErkJggg==");
cursor: ew-resize;
}
<span class="resizable-input"><input type="text" /><span>
Maybe this could help!! :)

How to make a vertical input field?

This is what I want. A vertical input field, the 'x' is the close button:
This is what I have so far:
*{
margin:0;
padding:0;
}
html,body{
height:100%;
width:100%;
}
.sidenav{
height:100%;
width:20%;
background:#111;
overflow-x:hidden;
box-sizing:border-box;
padding:calc((20% - 50px)/2);
}
.sidenav a{
position:relative;
bottom:18px;
font-size:90px;
color:#818181;
}
<div class='sidenav''>
<a>&times</a>
</div>
I know how to make a regular, bare-boned html input field:
<form>
<input type=text placeholder='enter name'></input>
<input type='submit' id='submit'></input>
</form>
EDIT: I want to integrate it to make a stylistically uniform, like this search bar from CodePen:
What you're looking for is transform: rotate().This takes a value in degrees, so you can rotate either to the left or to the right. rotate(90deg) goes from top to bottom, rotate(-90deg) goes from bottom to top.
You'll also probably want to make use of transform-origin to choose where the rotation gets based from, in order for the rotated text to align at the correct position.
Here's a minimal example:
input[type="text"] {
transform: rotate(-90deg);
transform-origin: left 0;
position: absolute;
bottom: 0;
}
<input type='text' placeholder='enter name'>
And here's a (rough) working example. Maximise the snippet to see it positioned correctly. You may need to adapt the positioning based on your page layout.
input[type="text"] {
position: absolute;
bottom: -150%;
left: 25%;
transform: rotate(-90deg);
transform-origin: left 0;
}
form {
position: relative;
}
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
width: 100%;
}
.sidenav {
height: 100%;
width: 20%;
background: #111;
overflow-x: hidden;
box-sizing: border-box;
padding: calc((20% - 50px)/2);
}
.sidenav a {
position: relative;
bottom: 18px;
font-size: 90px;
color: #818181;
}
<div class='sidenav'>
<form>
<input type='text' placeholder='enter name '>
<a>&times</a>
</form>
</div>
Hope this helps! :)
you may take a look at writing-mode.
The writing-mode CSS property defines whether lines of text are laid out horizontally or vertically and the direction in which blocks progress.
About MSIE https://msdn.microsoft.com/library/ms531187(v=vs.85).aspx
.sideway {
writing-mode: vertical-rl;
writing-mode: sideways-lr;/* FF*/
background: gray;
padding: 0.25em;
vertical-align:top;
}
form {
border: solid gray
}
<form><span class="sideway">
<input type=text placeholder='enter name' size=8/>
<input type='submit' id='X'/>
</span>
</form>
<edit> Chrome does not apply writing-mode on form element (bug?)
Work around possible: demo
.sideway {
font-size: 3em;
margin: 0 1em 0 0;
white-space: nowrap;
background: #333;
padding: 0.25em 0;
float: left;
width: 2em;
}
.sideway span {
vertical-align: top;
display: inline-block;
transform: translatey(100%) rotate(270deg);
transform-origin: 0 0;
}
.sideway span:before {
content: '';
padding-top: 100%;
float: left;
}
input {
font-size: 1em;
color: gray;
background: none;
border: none;
line-height: 0.8em;
vertical-align: middle;
outline: none;
}
[type="submit"] {
font-size: 2em;
vertical-align: middle;
width:1em;
}
form {
overflow: hidden;
border: solid #333 0.5em;
}
p {
overflow: hidden;
margin: 1em;
}
<form>
<p class="sideway">
<span>
<input type=text placeholder='enter name' size=8/>
<input type='submit' id='submit' value='&times'/>
</span>
</p>
<p>whatever else comes in your form</p>
</form>

Can't get input fields to stay inside the contact form's div

I really got stuck on something that should be simple. I've searched on Google for a fix, but couldn't find any. Most were saying to add {box-sizing: border-box;}, but I already had that.
HTML code:
<div class="row">
<form method="post" action="#" class="contact-form clearfix">
<div class="row">
<div class="col span-1-of-2">
<input type="text" name="name" id="name" placeholder="Name" required>
</div>
<div class="col span-1-of-2">
<input type="email" name="email" id="email" placeholder="Email" required>
</div>
</div>
<div class="row">
<textarea name="message" id="message" rows="4" placeholder="Message"></textarea>
</div>
<div class="row">
<input type="submit" name="submit" id="submit" value="SEND MESSAGE">
</div>
</form>
</div>
CSS code:
/* THE STANDARD STUFF */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body{
background-color: #fff;
color: #777;
font-size: 16px;
font-family: 'Raleway', sans-serif;
font-weight: 300;
text-rendering: optimizeLegibility;
overflow-x: hidden;
}
.clearfix{zoom:1;}
.clearfix:after{
content: '.';
clear: both;
display: block;
height: 0;
visibility: hidden;
}
.row{
width: 1170px;
margin: 0 auto;
}
/* FROM GRID.CSS */
.row:before,
.row:after {
content:"";
display:table;
}
.row:after {
clear:both;
}
.col {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.col:first-child { margin-left: 0; }
.span-1-of-2 {
width: 49.2%;
}
/* THE CONTACT STYLE */
.contact-form{
width: 80%;
margin: 0 auto;
}
input[type=text], input[type=email], textarea{
width: 100%;
padding: 10px;
margin-bottom: 15px;
border-radius: 3px;
border: 1px solid #ccc;
}
textarea{
height: 100px;
}
.contact-form #submit{
border: 0;
margin-top: 20px;
}
*:focus{
outline: none;
}
Here's how the form looks like: http://codepen.io/anon/pen/apVzyg
As you can see, the fields are being pushed to the right, instead of staying within the row and the contact form's container, which is set to 80%. For the life of me, I cannot figure out why this is happening. Maybe the mistake is in front of me, but I got tunnel vision by now.
I made this based on the instructor's style and example, which you can check here: http://codepen.io/anon/pen/VPrYqm
It's kind of similar to mine, except I don't use label and I use col 1-of-2.
The grid.css file is downloaded from responsivegridsystem(dot)com.
The contact-form parent container belongs to class .row and will get a fixed width of 1170px. Then contact-form is defined to be 80% of that size and margin auto. so margins will be 20% of 1170px, 10% on each side. You can fix it by removing the 1170px restriction. You could have a look at min-width and max-width properties to achieve a more adaptable layout.
The problem is arising because you are setting row width explicitly.
width: 1170px;
Remove this line and you'll get the desired rendering of your HTML.
See this pen: http://codepen.io/vici0us/pen/mRqJXK?editors=1100

Firefox size rendering vs other browser

Please see this jsfiddle
HTML:
<body>
<header>
<div id="top-header">
<div id="search-div">
<form method="get" name="search">
<input value="Search" id="search-button" type="submit">
<input name="term" id="search-box" type="search">
<div id="search-options">
<ul>
<li id="search-option-icon">0</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
<input name="search-type" id="search-type" type="hidden">
</div>
</form>
</div>
</div>
<div id="bottom-header">something here</div>
</header>
</body>
CSS:
*{
margin:0;
padding:0;
font-size:100%;
border:0 none;
}
body{
direction: rtl;
}
header{
position:relative;
width:100%;
height: 80px;
}
/*
--------------------------------------------------------
| header
--------------------------------------------------------
*/
header > div{
width: 100%;
position:relative;
position: relative;
}
#top-header{
background: #9600ee;
height: 52px;
}
#bottom-header{
background: white;
height: 29px;
border-bottom: 1px solid #d5d5d5;
box-shadow:0 1px 1px #e0e0e0;
}
#img-logo{
display: inline-block;
}
/*
--------------------------------------------------------
| header > search-div
--------------------------------------------------------
*/
#search-div{
width:432px;
position: absolute;
top:8px;
height: 36px;
left:0;
right:0;
margin:auto;
z-index: 3;
}
#search-options{
height: 36px;
width: 49px;
background: #FFFFFF;
background: linear-gradient(#FFFFFF,#e6e6e6);
text-align: center;
display: inline-block;
vertical-align: middle;
cursor: pointer;
left:0;
}
#search-options > ul > li{
display: none;
}
#search-option-icon{
display: block !important;
}
#search-options:hover > ul > li{
width: 49px;
background: red;
display: block;
}
#search-box{
display: inline-block;
height: 36px;
width: 325px;
right:49px;
padding:0 5px;
border-right:1px solid #9600ee;
border-left: 1px solid #d1d1d1;
}
#search-button{
height: 100%;
width: 48px;
background: #FFFFFF;
background: linear-gradient(#FFFFFF,#e6e6e6);
border-radius: 0 2px 2px 0;
}
I am going to create a page that its direction is Right to Left. I don't know why Firefox is showing a different result then other browsers?
What I see in Chrome:
What Firefox shows(Firefox 37):
What is the problem? And why is Firefox (or my Firefox) showing a different result?
Input elements are rendered depending on the browsers and OS with a different appearance. Chrome seems to apply box-sizing: border-box; to an input element as soon as you change the type to search, but Firefox doesn't do that (currently I would say that Firefox is right about that but I need to check this in the specs).
Firefox does not change the box-sizing for those elements and because the default box-sizing is content-box, the complete outer-width is width + padding + border (for more details you can look here CSS-Tricks: Box Sizing). As of that your #search-box in Firefox does not have an outer-width of 325px.
If you want to have better control about the outer-width of the elements you need to use border-box for box-sizing. You can change the box-sizing for your whole page using :
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
Code from site: Paul Irish: * { Box-sizing: Border-box } FTW
Updated jsfiddle using border-box.
Your #search-div is too narrow, making the elements crammed together. Your search divs are also out of order. I would suggest arranging them in the order of search-options, search-box, search-button, then adding float: left; to each of their styles as well as some margin-left: 20px; so they aren't right next to each other.
Your search-box also has a small width cutting off letters.
See this jsfiddle: http://jsfiddle.net/3qzb7q0d/1/
Something like:
#search-options {
display: inline-block;
float: left;
margin-left: 20px;
// whatever else
}
Add that to each search portion.
Increase the width of #search-button
Remove the width from #search-div

How to align a button to the right of text box without margin?

How can I align a button (submit) exactly to the right of a text or search box,
with the same height as the search box,
and without any horizontal white-space between search box and button ?
This is what I have
<input type="text" value="" placeholder="search text here" style="display: block; width: 100px; height: 32px; margin: 0px; padding: 0px; float: left;" />
<input type="submit" value=" OK " style="display: block; margin: 0px; width: 20px; height: 32px; padding: 0px; float: left; border-left: none;" />
http://jsfiddle.net/Ggg2b/
But neither is the button the same height as the textbox
, and more importantly, I don't seem to be able to get rid of that 0.5 to 1mm space between text-box and button.
<input type="text" value="" placeholder="search text here" class="txtbox" />
<input type="submit" value=" OK " class="btncls" />
.txtbox{
display: block;
float: left;
height: 32px;
width: 100px;
}
.btncls{
display: block;
float: left;
height: 40px;
margin: -1px -2px -2px;
width: 41px;
}
OR Check on Fiddle http://jsfiddle.net/Ggg2b/9/
To show your submit button at the right side of your search you only need to change some of your code as per given below. remove the left align from the code of button. and give the to the button is 34 px
<input type="text" value="" placeholder="search text here" style="display: block; width: 100px; height: 32px; margin: 0px; padding: 0px; float: left;" />
<input type="submit" value=" OK " style="display: block; margin: 0px; width: 40px; height: 34px; padding: 0px; " />
Add a height to the button using CSS.
.btn {
font-size: 16px;
border: 0;
height: 34px;
margin: 0;
float:left;
}
Then add height to the textbox using style attribute and check whether the heights match.
<input type="text" value="" placeholder="search text here" style="height:28px;float:left;margin:0;" />
<input type="submit" value=" OK " class='btn' />
fiddle demo:http://jsfiddle.net/suhailvs0/Ggg2b/7/
One way to approach this is by putting the text input and the button in a container which uses grid layout. Using the below simple code, you will need to add width restraints on the container as it will expand to the max possible width:
.joined {
display: grid;
grid-template-columns: 1fr auto;
}
<section class="joined">
<input type="text"></input>
<button>Go</button>
</section>
Here is an example showing how it will autosize/grow with other size settings applied:
.joined-2 {
display: grid;
grid-template-columns: 1fr auto;
min-width:280px;
width: 80vw;
}
input {
height:100px;
}
<section class="joined-2">
<input type="text"></input>
<button>Go</button>
</section>
put this in a paragrapgh tag and there no need for float:left
<p><input type="text" value="" placeholder="search text here" style="display: block; width: 100px; height: 32px; margin: 0px; padding: 0px;" />
<input type="submit" value=" OK " style="display: block; margin: 0px; width: 20px; height: 32px; padding: 0px; " /></p>
Increase the width, say for example
<input type="submit" value=" OK " style="display: block; margin: 0px; width: 100px; height: 32px; padding: 0px; float: left;" />
I made some changes in HTML markup. I wrapped the input boxes in divs and assigned width and height to the divs instead of the input boxes.
HTML
<div class="mainCls">
<div class="textCls">
<input type="text" value="" placeholder="search text here" />
</div>
<div class="submitCls">
<input type="submit" value=" OK " />
</div>
</div>
CSS
input[type=text], input[type=submit] {
margin: 0px;
padding: 0px;
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
display: block;
}
div.mainCls {
height: 35px;
position: relative;
border: 1px solid green;
display:inline-block;
}
.mainCls>div {
float: left;
position: relative;
height: 100%;
}
.textCls {
width: 100px;
}
.submitCls {
width: 30px;
}
Working Fiddle
If the input boxes are of fixed width, as in your case, then there is no need of child div's which I used above. You can just add left: 100px; /* width of the input text */ to the submit button.
Put them into a container, set fix width and height of the container. And set the elements in the container only percentage width. If you will use border-box: sizing; you can add them border and pagging without change container's width and height.
HTML:
<div class="input-box">
<input class="input-1" type="text" value="" placeholder="search text here" />
<input class="input-2" type="submit" value="OK" />
</div>
CSS:
.input-1, .input-2{
display: inline-block;
height: 100%;
margin: 0;
padding: 0;
float: left;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
}
.input-1{
width: 70%; /* input-1 + input-2 = 100% */
}
.input-2{
width: 30%; /* input-1 + input-2 = 100% */
}
.input-box{
height: 32px; /* Own value - full height */
width: 200px; /* Own value - full width */
}
Live demo. Now new, edited.
http://jsfiddle.net/Ggg2b/14/
Ah, I got it.
There are two problems at once.
First, there may be no white-space between end of input 1 and start of input 2.
A known IE bug.
And then, for the buttons being the same size as the text-box, it's necessary to apply the box-sizing property
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
Like this:
label, input {
margin: 0.1em 0.2em;
padding: 0.3em 0.4em;
border: 1px solid #f90;
background-color: #fff;
display: block;
height: 50px;
float: left;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
}
input[type=text] {
margin-right: 0;
border-radius: 0.6em 0 0 0.6em;
}
input[type=text]:focus {
outline: none;
background-color: #ffa;
background-color: rgba(255,255,210,0.5);
}
input[type=submit] {
margin-left: 0;
border-radius: 0 0.6em 0.6em 0;
background-color: #aef;
}
input[type=submit]:active,
input[type=submit]:focus {
background-color: #acf;
outline: none;
}
<form action="#" method="post">
<input type="text" name="something" id="something" /><input type="submit" value="It's a button!" />
</form>
I accomplished this same task for a search box, I hope this may help someone.
<input type="text" name="id" id="seacrhbox" class="form-control"
placeholder="Type to search" style="width:300px;display:inline-block;margin-right: 25px;"/>
<input type="submit" value="Search" class="btn-success" style="height:32px;
width:80px;font-weight: 600;" />
Additionaly: (not related to the question)
If you would like to retain the value of a textbox in an asp/mvc use:
value="#Request["id"]" but if you want to do it in html try this