Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to right-align form input boxes?

I have a seemingly easy problem to solve, but am struggling. How do I get these two inputs to align to the right of the form, without using the BR element ?

<!DOCTYPE html> <html> <head>     <style type="text/css">     form {         text-align: right;     }     input {         width: 100px;     }     </style> </head>  <body>     <form>          <input name="declared_first" value="above" />           <br/> <!-- I want to get rid of this -->           <input name="declared_second" value="below" />     </form> </body> </html> 

I just want the first input to appear above the second input, both on the right hand side.

like image 410
ban-geoengineering Avatar asked Aug 24 '12 18:08

ban-geoengineering


People also ask

How do I align text boxes to the right?

text-align:right; will only right align text elements. It appears that your are using bootstrap. You could try giving your form a class of pull-right , which is a bootstrap class for float right.

How do I move my input box to the right?

if you want to move everything to right, use css "float: right". @DiGiTAL_DOMAiN: You can add a margin-right to push it back a bit.


2 Answers

You can use floating to the right and clear them.

form {    overflow: hidden;  }  input {    float: right;    clear: both;  }
<form>    <input name="declared_first" value="above" />    <input name="declared_second" value="below" />  </form>

You can also set a right-to-left direction to the parent and restore the default left-to-right on the inputs. With display: block you can force them to be on different lines.

form {    direction: rtl;  }  input {    display: block;    direction: ltr;  }
<form>    <input name="declared_first" value="above" />    <input name="declared_second" value="below" />  </form>

Or the modern way, flexbox layout

form {    display: flex;    flex-direction: column;    align-items: flex-end;  }
<form>    <input name="declared_first" value="above" />    <input name="declared_second" value="below" />  </form>
like image 164
Oriol Avatar answered Oct 17 '22 03:10

Oriol


Try use this:

<html> <body>    <input type="text" style="direction: rtl;" value="1">    <input type="text" style="direction: rtl;" value="10">    <input type="text" style="direction: rtl;" value="100"> </body> </html> 
like image 37
Marco Avatar answered Oct 17 '22 02:10

Marco