Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the text inside an <input> tag get cut off even if there's already a padding?

Tags:

html

css

Ok so I found out that the text inside an <input> tag still gets cut off even though the <input> tag already has a padding. You'll notice it more when you set your font style to anything cursive.

Take a look at this image:

The first text box in the screenshot is an input of type=text and the second text box is just a div. The input text box cuts off the tail of character 'j', while the div text box does not.

HTML:

<input type="text" value="juvenescent" />
<div>juvenescent</div>

CSS:

input, div {
  font-family: cursive;
  font-size: 2em;
  padding: 15px 20px;
  margin-bottom: 10px;
  width: 300px;
  border: 1px solid black;
}

div {
  background-color: white;
}

Here is a link to the jsfiddle: https://jsfiddle.net/9eLzqszx

What would be the workaround here? Obviously, I want the padding of the input text box to NOT cut the text inside it.

like image 395
Jaye Renzo Montejo Avatar asked Jul 01 '16 16:07

Jaye Renzo Montejo


People also ask

How do you keep labels inside input?

There are two ways to pair a label and an input. One is by wrapping the input in a label (implicit), and the other is by adding a for attribute to the label and an id to the input (explicit). Think of an implicit label as hugging an input, and an explicit label as standing next to an input and holding its hand.

Can we wrap text in input field?

You can't wrap text in a text input box, so perhaps you should use a textarea.

How do I fix a text box in HTML?

The <textarea> tag defines a multi-line text input control. The <textarea> element is often used in a form, to collect user inputs like comments or reviews. A text area can hold an unlimited number of characters, and the text renders in a fixed-width font (usually Courier).

How do you make an input tag editable?

Answer: Use the HTML5 contenteditable Attribute You can set the HTML5 contenteditable attribute with the value true (i.e. contentEditable="true" ) to make an element editable in HTML, such as <div> or <p> element.


1 Answers

It looks like the curve of the J goes past the left-hand side of what the browser considers to be the edge of the letter. Instead of using padding for both sides, use padding for top/right/bottom and instead use text-indent for the left, it should do the trick!

input {
  font-family: cursive;
  font-size: 2em;
  padding: 15px 20px 15px 0;
  font-style:italic;
  margin-bottom: 10px;
  width: 300px;
  border: 1px solid black;
  text-indent: 20px;
}

https://jsfiddle.net/will0220/pxrs321f/3/

like image 154
will Avatar answered Oct 18 '22 08:10

will