开发者

CSS Label, Checkboxs, and Inputform Lineup

What would be a proper css method to make the following so it开发者_如何学运维 is the same with the exception that the text input fields vertically line up along their left side?

CSS Label, Checkboxs, and Inputform Lineup

So the check boxes will still be right up against the input fields and in between the label and input fields, but the input fields still all light up.

Current HTML:

<p><label for="search_uri">Uri:</label><input id="search_uri" type="text" name="Uri" /></p>
<p><label for="search_server">Server:</label><input type="checkbox" name="server_like" /><input id="search_server" type="text" name="Server" /></p>
<p><label for="search_host">Host:</label><input id="search_host" type="text" name="Host" /></p>

Current CSS:

label {
        font-size: 90%;
        float:left;
        width: 15em;
}


Why not just use a negative margin?

.checkbox {margin-left: -16px;}

Depending on the rest of your setup might require a bit of tweaking for cross-browser pixel-perfectness.

I would personally probably also just float both the labels and the inputs and get rid of the <p>:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style>
        label {
            display: block;
            font-size: 90%;
            width: 15em;
            clear:left;
        }

        label, input {
            float:left;
        }

        input[type=checkbox]
        /* use .checkbox and add 'class="checkbox"' if you want to support IE6*/
        {
            margin-left: -2em;
        }

    </style>
</head>
<body>
    <form>
        <label for="search_uri">Uri:</label>
        <input id="search_uri" type="text" name="Uri" />

        <label for="search_server">Server:</label>
        <input type="checkbox" name="server_like" />
        <input id="search_server" type="text" name="Server" />

        <label for="search_host">Host:</label>
        <input id="search_host" type="text" name="Host" />
    </form>
</body>
</html>


Do this.

HTML Markup:

<form><fieldset>
<legend>Login Details</legend>
<label>Your Email:</label><input type="text" name="email" maxlength="32" />
<label>Your Password:</label><input type="password" name="password" maxlength="30" />
</fieldset>
<input id="submit" type="submit" value="Create Account" /></form>

Css Markup:

fieldset {padding: 10px 0;}
legend {font-weight: bold; padding: 0 0 3px 0; color: #f00;}
input {padding: 2px; border-radius: 3px; width: 130px; float: left; margin: 0 0 5px 0;}
label {float: left; width: 150px; text-align: right; margin: 1px 3px 0 0;}
#submit {width: auto; margin: 0 0 0 153px;}

Then add a width to your form, depending on the input sizes, with your checkbox, just float it in between and use margins.


I would do something like this;

<div class="label">Uri:</div><div class="field"><input type="text" /></div>

Then give the div with the class 'label' an default width and float them next to eachother.

EDIT: Saw you changed your post;

<label for="search_uri">Uri:</label>
<input id="search_uri" type="text" name="Uri" />

Your css could be something like

label
{
    width: 150px;
    float:left;
    clear:both; /*Clear the previous row with label and field, not sure if this is needed*/
}
input
{
    float:left;
}


If your form is small, you can just use a <table>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜