如何用CSS控制字段集的定位?

发布于 2024-07-30 10:01:18 字数 918 浏览 2 评论 0原文

我有以下代码:

<fieldset>
    <legend>
        <strong>Personal Information</strong>
    </legend>
    <ul>
        <li>
            <label for="first_name">First Name</label><br />
            <input type="text" id="first_name" name="first_name" value="" maxlength="30" />
        </li>
        ...
    </ul>
</fieldset>
<fieldset>
    <legend>
        <strong>Car Information</strong>
    </legend>
    <ul>
        <li>
            <label for="car_make">Make</label><br />
            <input type="text" id="car_make" name="car_make" value="" maxlength="30" />
        </li>
        ...
    </ul>
</fieldset>

现在所有内容都在左侧,其中第二个字段集(汽车信息)位于第一个字段集(个人信息)的正下方。

我希望汽车信息字段集位于个人信息字段集的右侧,以便它们并排。 使用CSS,我该如何做到这一点?

I have the following code:

<fieldset>
    <legend>
        <strong>Personal Information</strong>
    </legend>
    <ul>
        <li>
            <label for="first_name">First Name</label><br />
            <input type="text" id="first_name" name="first_name" value="" maxlength="30" />
        </li>
        ...
    </ul>
</fieldset>
<fieldset>
    <legend>
        <strong>Car Information</strong>
    </legend>
    <ul>
        <li>
            <label for="car_make">Make</label><br />
            <input type="text" id="car_make" name="car_make" value="" maxlength="30" />
        </li>
        ...
    </ul>
</fieldset>

Right now everything is on the left hand side where the second fieldset (car information) is right below the first fieldset (personal information).

I would like the car information fieldset to be on the right hand side of the personal information fieldset so they are side by side. Using css, how would I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

↘人皮目录ツ 2024-08-06 10:01:18

由于字段集被视为块,因此您需要使用

fieldset {
    width: 200px;
    float: left;
}

Or 任何您想要的字段集宽度。

Since fieldsets are considered blocks, you need to use

fieldset {
    width: 200px;
    float: left;
}

Or whatever you want for the width of the fieldsets.

ぇ气 2024-08-06 10:01:18

您可以做的是将两个字段集浮动到左侧。 css 看起来像这样:

fieldset {
    float: left;
    width: 200px;
}

这将影响页面上的每个字段集,因此如果您只想隔离特定字段集,请使用 CSS 类

<style>
    .FloatLeft { float: left; width: 200px;}
</style>

<fieldset class="FloatLeft">

What you can do is float both fieldsets to the left. The css would look like this:

fieldset {
    float: left;
    width: 200px;
}

This is going to effect every fieldset on the page, so if you want to isolate only specific fieldsets use css classes:

<style>
    .FloatLeft { float: left; width: 200px;}
</style>

<fieldset class="FloatLeft">
我也只是我 2024-08-06 10:01:18

正如他们所说,但您也可以将汽车信息浮动到右侧,这使您的优势是无论宽度如何,都始终与该边缘齐平(如果这很重要)。

What they said, but you can also float the car information right, which gives you the advantage of always being flush against that edge no matter the width, if that's important.

淡写薰衣草的香 2024-08-06 10:01:18
fieldset {
  -moz-border-radius:5px;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  width: 200px;
  float: left;    
}
fieldset {
  -moz-border-radius:5px;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  width: 200px;
  float: left;    
}
百合的盛世恋 2024-08-06 10:01:18

如果您为字段集指定宽度并将其向左浮动,则如下所示:

HTML:

<fieldset class="myFieldSet">
    <legend>
        <strong>Personal Information</strong>
    </legend>
    <ul>
        <li>
            <label for="first_name">First Name</label><br />
            <input type="text" id="first_name" name="first_name" value="" maxlength="30" />
        </li>
        ...
    </ul>
</fieldset>
<fieldset class="myFieldSet">
    <legend>
        <strong>Car Information</strong>
    </legend>
    <ul>
        <li>
            <label for="car_make">Make</label><br />
            <input type="text" id="car_make" name="car_make" value="" maxlength="30" />
        </li>
        ...
    </ul>
</fieldset>

CSS:

.myFieldSet
{
width:300px;
float:left;
}

If you assign a width to your fieldsets and float the to the left, something like this:

HTML:

<fieldset class="myFieldSet">
    <legend>
        <strong>Personal Information</strong>
    </legend>
    <ul>
        <li>
            <label for="first_name">First Name</label><br />
            <input type="text" id="first_name" name="first_name" value="" maxlength="30" />
        </li>
        ...
    </ul>
</fieldset>
<fieldset class="myFieldSet">
    <legend>
        <strong>Car Information</strong>
    </legend>
    <ul>
        <li>
            <label for="car_make">Make</label><br />
            <input type="text" id="car_make" name="car_make" value="" maxlength="30" />
        </li>
        ...
    </ul>
</fieldset>

CSS:

.myFieldSet
{
width:300px;
float:left;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文