How to display text fields one by one without switching?

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>
Run codeHide result

How can I create text fields under another without changing?

Thanks in advance.

+4
source share
2 answers

You can do this with inline-blockadded tags <span>.

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>
Run codeHide result

Or, css table.

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>
Run codeHide result
+1
source

enter the left field in the input field for the faculty

+1
source

All Articles