Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align cursor to placeholder starting position

I have the following HTML and CSS code and the output. When I click the input boxes I want my cursor to be exactly just on the left of the placeholder text. But when I click the input the box the cursor shows up at the very start of the the input box. How can i align the cursor to the placeholder starting character on focus. Thanks

HTML

<head>
    <title>AUMC-Student Portal</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css2/paper.css" rel="stylesheet" media="screen">
    <link href="css2/myCSS.css" rel="stylesheet" media="screen">
</head>

<body>
    <div class="Login-Form-Container">
        <form class="Inner-Portion">
            <div>
                <input class="form-control" type="text" placeholder="Username" />
            </div>
            <br>

            <div>
                <input class="form-control" type="password" placeholder="Password" />
            </div>
            <br>

            <select class="form-control controls">
                <option selected>Laptop</option>
                <option value="">Mouse</option>
                <option value="">Keyboard</option>
                <option value="">Monitor</option>
                <option value="">Hello World</option>
            </select>
            <br>
            <br>
            <button type="button" class="btn btn-default">Forgot</button>
            <button type="button" class="btn btn-primary">Login</button>
            <form/>
    </div>
</body>

</html>

CSS

body {
    background-color: #293037;
    background-size: 1500px;
}

.Login-Form-Container {

    background-color: dodgerblue;
    width: 400pt;
    height: 310pt;
    text-align: center;
    margin: 0 auto;
}

.Inner-Portion  {
    background-color: whitesmoke;
    width: 400pt;
    height: 300pt;
    padding-top: 57pt;

}


.controls , .Inner-Portion div{
    margin: 0px auto;
    width: 300px;
}


.form-control::-webkit-input-placeholder {
    padding: 55px;
}


.Inner-Portion div{
    border: solid 1px #DDDDDD;
}

.btn-default , .btn-primary {
    width: 150px;
}

OUTPUT enter image description here

like image 309
Syed Ahmed Jamil Avatar asked Oct 26 '25 10:10

Syed Ahmed Jamil


2 Answers

You can use text-indent property.

input.form-control {
  box-sizing: border-box;
  width: 100%;
  text-indent: 30px;
}

jsFiddle

Or just set some padding-left for it.

input.form-control {
  box-sizing: border-box;
  width: 100%;
  padding-left: 30px;
}

jsFiddle

like image 195
Stickers Avatar answered Oct 29 '25 00:10

Stickers


You may add:

input.form-control {
    width: 100%;
   padding-left: 55px;
}

and remove .form-control::-webkit-input-placeholder.

The snippet:

body {
    background-color: #293037;
    background-size: 1500px;
}

.Login-Form-Container {

    background-color: dodgerblue;
    width: 400pt;
    height: 310pt;
    text-align: center;
    margin: 0 auto;
}

.Inner-Portion  {
    background-color: whitesmoke;
    width: 400pt;
    height: 300pt;
    padding-top: 57pt;

}


.controls , .Inner-Portion div{
    margin: 0px auto;
    width: 300px;
}


input.form-control {
    width: 100%;
    padding-left: 55px;
}

.Inner-Portion div{
    border: solid 1px #DDDDDD;
}

.btn-default , .btn-primary {
    width: 150px;
}
<div class="Login-Form-Container">
    <form class="Inner-Portion">
        <div>
            <input class="form-control" type="text" placeholder="Username" />
        </div>
        <br>

        <div>
            <input class="form-control" type="password" placeholder="Password" />
        </div>
        <br>

        <select class="form-control controls">
            <option selected>Laptop</option>
            <option value="">Mouse</option>
            <option value="">Keyboard</option>
            <option value="">Monitor</option>
            <option value="">Hello World</option>
        </select>
        <br>
        <br>
        <button type="button" class="btn btn-default">Forgot</button>
        <button type="button" class="btn btn-primary">Login</button>
        </form>
</div>
like image 37
gaetanoM Avatar answered Oct 29 '25 00:10

gaetanoM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!