Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display textboxes one under another without shifting?

Tags:

html

css

I have the following HTML code:

<div>
    <p><label>Faculty <input type="text" class = "f"></label></p>
    <p><label >Department<input type="text" class = "f"></label></p>
</div>

How can I make textboxes appear one under another without shifting?

like image 929
Michael Avatar asked Nov 01 '22 04:11

Michael


1 Answers

You could do it with inline-block, additional <span> tags added.

div > p > label > span {
    display: inline-block;
    width: 90px;
}
<div>
    <p>
        <label>
            <span>Faculty</span>
            <input type="text" class="f" />
        </label>
    </p>
    <p>
        <label>
            <span>Department</span>
            <input type="text" class="f" />
        </label>
    </p>
</div>

Or, the css table way.

div > p > label {
    display: table;
    table-layout: fixed;
}
div > p > label > span {
    display: table-cell;
}
div > p > label > span:first-child {
    width: 90px;
}
<div>
    <p>
        <label>
            <span>Faculty</span>
            <span><input type="text" class="f" /></span>
        </label>
    </p>
    <p>
        <label>
            <span>Department</span>
            <span><input type="text" class="f" /></span>
        </label>
    </p>
</div>
like image 141
Stickers Avatar answered Nov 11 '22 03:11

Stickers