Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

positioning a text inside an input tag

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
Hallo,
does someone know how to position the text inside an input tag (textarea). If the textarea is a little bit higher than the text, the cursor automatically position itself on top position. I would like to control this but I've no idea how... thanks for suggestions
 
Hi,

You can use CSS to control the layout -however, I'm not sure exactly what you're asking ... could you please post a (brief) example.

Cheers


Jakob
 
hallo jakob,
well, the problem is that if I have a textfield that 25 px high and the text inside the textfield is going to be 12px high, then the text will be aligned on the top of the textfield. The example:

<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<style>
input.text {border-color: #000000;
border-width:1px;
font-family: arial;
font-size:12px;
display:inline;
width: 192px;
height :25px;}
</style>
</head>
<body>
<form name="form1" method="post" action="">
<input type="textarea" name="textarea" value="hallo" class="text">
</form>
</body>
</html>
 
Apply some padding to the box. It's not really automatic centering, but you can make it work:
Code:
<html>
  <head>
    <link rel="stylesheet" href="style.css" type="text/css" />
    <style>
      input.text {border-color: #000000; 
           border-width: 1px; 
           font-family: Arial; 
           font-size: 12px;         
           display: inline;
           width: 192px;
           height: 25px;
	   padding: 3px 2px 3px 2px;
      }
    </style>
  </head>
  <body>
    <form name="form1" method="post" action="">
      <input type="textarea" name="textarea" value="hallo" class="text">
    </form>
  </body>
</html>
 
karerda,

Add the following to your CSS definition for the input box:

Code:
line-height: 25px;

Hope this helps,
Dan
 

Sorry - forgot to mention.... You can increase or decrease that vaue to move the text (and thus the cursor, too) up or down accordingly.

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top